10
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

さくらのレンタルサーバでRubyを使う

さくらのレンタルサーバでRubyを使いたい。

$ ruby -v
ruby 1.8.7 (2012-10-12 patchlevel 371) [amd64-freebsd9]

えぇ…

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を自前ビルドします。(バージョン番号は適宜読み替えてください)

$ 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"

つらい

参考文献

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
10
Help us understand the problem. What are the problem?