1. takemaro

    Posted

    takemaro
Changes in title
+さくらのレンタルサーバでRubyを使う
Changes in tags
Changes in body
Source | HTML | Preview
@@ -0,0 +1,117 @@
+[さくらのレンタルサーバ](https://www.sakura.ne.jp/)でRubyを使いたい。
+
+```
+$ ruby -v
+ruby 1.8.7 (2012-10-12 patchlevel 371) [amd64-freebsd9]
+```
+
+えぇ…
+
+[rbenv](https://github.com/rbenv/rbenv)使って自前で入れます。
+
+```
+$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
+$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
+$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
+$ source ~/.bash_profile
+$ mkdir -p ~/.rbenv/plugins
+$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
+```
+
+これでrbenvとruby-buildの準備ができました。
+
+```
+$ rbenv install 2.6.1
+ruby-build: TMPDIR=/tmp cannot hold executables (partition possibly mounted with `noexec`)
+```
+
+(バージョン番号は適宜読み替えてください)
+`/tmp`に実行権限がないと怒られました。レンタルサーバーだししょうがないね。
+
+```
+$ mkdir tmp
+$ TMPDIR=~/tmp rbenv install 2.6.1
+Downloading ruby-2.6.1.tar.bz2...
+-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.1.tar.bz2
+Installing ruby-2.6.1...
+
+BUILD FAILED (FreeBSD 9.1-RELEASE-p24 using ruby-build 20190130)
+
+Inspect or clean up the working tree at /home/example/tmp/ruby-build.00000000000000.00000
+Results logged to /home/example/tmp/ruby-build.00000000000000.00000.log
+
+Last 10 log lines:
+ xmlrpc 0.3.0
+installing rdoc: /home/example/.rbenv/versions/2.6.1/share/ri/2.6.0/system
+installing html-docs: /home/example/.rbenv/versions/2.6.1/share/doc/ruby
+installing capi-docs: /home/example/.rbenv/versions/2.6.1/share/doc/ruby
+The Ruby openssl extension was not compiled.
+ERROR: Ruby install aborted due to missing extensions
+Configure options used:
+ --prefix=/home/example/.rbenv/versions/2.6.1
+ LDFLAGS=-L/home/example/.rbenv/versions/2.6.1/lib
+ CPPFLAGS=-I/home/example/.rbenv/versions/2.6.1/include
+```
+
+つらい。
+
+[OpenSSL](https://www.openssl.org/)を自前ビルドします。(バージョン番号は適宜読み替えてください)
+
+```
+$ mkdir -p openssl/src
+$ cd openssl/src
+$ wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
+$ tar -zxvf openssl-1.1.1a.tar.gz
+$ cd openssl-1.1.1a
+$ ./config --prefix=~/openssl/openssl
+$ make
+$ make test
+$ make install
+```
+
+いざ。
+
+```
+$ TMPDIR=~/tmp RUBY_CONFIGURE_OPTS=--with-openssl-dir=~/openssl/openssl rbenv install 2.6.1
+Downloading ruby-2.6.1.tar.bz2...
+-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.1.tar.bz2
+Installing ruby-2.6.1...
+Installed ruby-2.6.1 to /home/example/.rbenv/versions/2.6.1
+```
+
+長く苦しい戦いだった…
+
+```
+$ rbenv shell 2.6.1
+$ ruby -v
+ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-freebsd9.1]
+```
+
+---
+
+ちなみにRuby2.4までならOpenSSL自前で用意しなくてもビルドが通るんだけど、`gem install`が落ちる。
+
+```
+$ rbenv shell 2.4.5
+$ ruby -v
+ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-freebsd9.1]
+$ gem install bundle
+ERROR: Could not find a valid gem 'bundle' (>= 0), here is why:
+ Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://api.rubygems.org/specs.4.8.gz)
+```
+
+なぜなのか
+
+```
+$ rbenv shell 2.4.5
+$ ruby -ropenssl -e "p OpenSSL::OPENSSL_VERSION"
+"OpenSSL 0.9.8zf 19 Mar 2015"
+```
+
+つらい
+
+## 参考文献
+
+- [Home · rbenv/ruby-build Wiki · GitHub]( https://github.com/rbenv/ruby-build/wiki):ruby-buildのオプションとかはこのへんに書いてある
+- [openssl/INSTALL at master · openssl/openssl · GitHub](https://github.com/openssl/openssl/blob/master/INSTALL):OpenSSLのconfigure optionsとかはtarballの`INSTALL`に書いてある
+- [Bundler: How to troubleshoot RubyGems and Bundler TLS/SSL Issues](https://bundler.io/v1.16/guides/rubygems_tls_ssl_troubleshooting_guide.html)