头图

Reference original: https://gist.github.com/akdetrick/7604130
Based on the translation of the original text, this article adds sporadic solutions to the problems that occur in actual operation.

rvm vs rbenv

At first, I saw that RVM has more functions than rbenv, so I chose RVM to manage the ruby version, but after a period of use, I found that rbenv is more convenient to control the ruby version, and the setting of Gemset is somewhat troublesome, and the setting is not good. Even rails Errors are reported when creating projects. So I simply replaced it with rbenv.

1) remove RVM from your system


First, to remove RVM.

The following commands etc. allow you to clean up the RVM installation files and all versions of Ruby installed via RVM.

 # rvm 的"自爆"模式, 将自动删除安装的ruby和自身的文件
$ rvm implode

# 偶尔会有因权限问题导致 ~/.rvm 删除不掉的问题
$ sudo rm -rf ~/.rvm

$ gem uninstall rvm
$ rm ~/.rvmrc
$ rm /etc/rvmrc

2) remove any remaining traces of RVM


Remove all settings associated with rvm reference paths from the following files

  • .profile
  • .bash_profile
  • .bashrc

zsh also needs to be modified:

  • .zshrc

3) install rbenv


Install rbenv and ruby-build plugin with Homebrew

The installation of rbenv can also refer to rbenv's own documentation: https://github.com/rbenv/rbenv#installation

 $ brew update
$ brew install rbenv ruby-build

4) install rubies for rbenv


Install the required ruby version using rbenv

 # 列出可安装的ruby稳定版本:
$ rbenv install -l

# 安装指定版本的ruby:
$ rbenv install 2.0.0-p247

Note: If there is a problem after installing a new ruby version or gem, run the $ rbenv rehash command

5) switching ruby versions in rbenv


Switch the ruby version used

There are two ways to switch the version of ruby used

Specify the ruby version used in the project path

Most ruby project paths include a .ruby-version file that specifies the version of ruby used in the project.

Manually change the version

 # 列出所有已安装,可使用的ruby版本
$ rbenv versions

# 设置在当前目录下使用的版本
$ rbenv local 3.0.4

# 设置全局使用版本
$ rbenv global 3.0.4

6) install the bundler gem


Install bundler gem

We recommend that you install bundler, it is an essential tool in ruby use, bundler can help you manage various gem packages that your project depends on.

 $ gem install bundler

7) never fight with RVM again


PS: Problems encountered in the process

Error when rbenv installs ruby: BUILD FAILED

The specific error content was not saved in time, and a similar content was found on so:

https://stackoverflow.com/questions/23177652/rbenv-install-ruby-build-failed

It's just that the problem described is similar, but I didn't solve the problem with the top upvote answer in the entry, I used this one instead:

so capture

 sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

I don't know if it took a long time to reinstall CommandLineTools because the entire CommandLineTools folder was deleted. In short, after installing CommandLineTools, rbenv can install ruby normally.


alfredhot
2 声望1 粉丝

引用和评论

0 条评论