LoginSignup
1
0

More than 3 years have passed since last update.

HomebrewでrbenvをmacOS Sierra 10.12にインストールして指定したバージョンのRubyをつかう

Last updated at Posted at 2019-07-28

前提

Homebrewがインストールされていること

rbenvをインストールする

<コンピューター名>:~ <ユーザー名>$ brew install rbenv
==> Installing dependencies for rbenv: openssl, pkg-config and ruby-build
==> Installing rbenv dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2s.sierra.bottl
==> Downloading from https://akamai.bintray.com/e5/e556bbb8902700cd3cb896e0635cc
######################################################################## 100.0%
==> Pouring openssl-1.0.2s.sierra.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2s: 1,795 files, 12.4MB
==> Installing rbenv dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2.sierra.bo
==> Downloading from https://akamai.bintray.com/8e/8eb723bfc03cd468d779d54d015d4
######################################################################## 100.0%
==> Pouring pkg-config-0.29.2.sierra.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pkg-config
Target /usr/local/bin/pkg-config
is a symlink belonging to pkg-config. You can unlink it:
  brew unlink pkg-config

To force the link and overwrite all conflicting files:
  brew link --overwrite pkg-config

To list all files that would be deleted:
  brew link --overwrite --dry-run pkg-config

Possible conflicting files are:
/usr/local/bin/pkg-config -> /usr/local/Cellar/pkg-config/0.28/bin/pkg-config
/usr/local/share/aclocal/pkg.m4 -> /usr/local/Cellar/pkg-config/0.28/share/aclocal/pkg.m4
/usr/local/share/doc/pkg-config/pkg-config-guide.html
/usr/local/share/doc/pkg-config/pkg-config-guide.html
/usr/local/share/man/man1/pkg-config.1 -> /usr/local/Cellar/pkg-config/0.28/share/man/man1/pkg-config.1
==> Summary
🍺  /usr/local/Cellar/pkg-config/0.29.2: 11 files, 627.1KB
==> Installing rbenv dependency: ruby-build
==> Downloading https://github.com/rbenv/ruby-build/archive/v20190615.tar.gz
==> Downloading from https://codeload.github.com/rbenv/ruby-build/tar.gz/v201906
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/20190615: 448 files, 225.5KB, built in 5 seconds
==> Installing rbenv
==> Downloading https://homebrew.bintray.com/bottles/rbenv-1.1.2.sierra.bottle.t
######################################################################## 100.0%
==> Pouring rbenv-1.1.2.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/rbenv/1.1.2: 36 files, 65.1KB
==> Caveats
==> openssl
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

rbenvのバージョンを確認する

<コンピューター名>:~ <ユーザー名>$ rbenv -v
rbenv 1.1.2

インストールできるRubyのバージョンを確認する

<コンピューター名>:~ <ユーザー名>$ rbenv install -l
Available versions:
  (省略)
  2.6.0-dev
  2.6.0-preview1
  2.6.0-preview2
  2.6.0-preview3
  2.6.0-rc1
  2.6.0-rc2
  2.6.0
  2.6.1
  2.6.2
  2.6.3
  (省略)

バージョン2.6.3をインストールする

rbenv install 2.6.3

インストールされているバージョンを確認する

<コンピューター名>:~ <ユーザー名>$ rbenv versions
* system (set by /Users/<ユーザー名>/.rbenv/version)
  2.6.3

rbenvで使用するRubyのバージョンを2.6.3にする

<コンピューター名>:~ <ユーザー名>$ rbenv global 2.6.3

rbenvで使用するRubyのバージョンを確認する

<コンピューター名>:~ <ユーザー名>$ rbenv versions
  system
* 2.6.3 (set by /Users/<ユーザー名>/.rbenv/version)

rubyコマンドからバージョンを確認する

<コンピューター名>:~ <ユーザー名>$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

MacにデフォルトでインストールされているRubyのバージョンになってしまっている

実行されているRubyの場所を確認する

<コンピューター名>:~ <ユーザー名>$ which ruby
/usr/bin/ruby

MacにデフォルトでインストールされているRubyの場所になってしまっている

.bash_profileを開く

<コンピューター名>:~ <ユーザー名>$ open .bash_profile

以下を追記する

eval "$(rbenv init -)"

以下でbash_profileを実行する

<コンピューター名>:~ <ユーザー名>$ source ./bash_profile

実行されているRubyの場所を確認する

<コンピューター名>:~ <ユーザー名>$ which ruby
/Users/<ユーザー名>/.rbenv/shims/ruby

homebrewでインストールしたRubyの場所が表示される

rubyコマンドからバージョンを確認する

<コンピューター名>:~ <ユーザー名>$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin16]

homebrewでインストールしたRubyのバージョンが表示される

疑問

結局パスの設定をする必要はないのか?

参考

https://weblabo.oscasierra.net/ruby-install-rbenv-homebrew-macos/
https://easyramble.com/rbenv-ruby-version-trouble.html
https://www.grami-sensei.com/ruby/0/1/4
https://weblabo.oscasierra.net/ruby-install-rbenv-homebrew-macos/

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0