在新的 Mac OS Sierra 上的 Rails 上安装 Ruby

Installing Ruby on Rails on a new Mac OS Sierra

我正在学习编码并尝试将 Rails 项目从云开发环境转移到我的 Mac 和 OS Sierra 上的本地项目。但是,我在设置 ruby 版本和安装 rails.

时遇到问题

我已经安装了用于安装 rbenv 的 Homebrew。使用 rbenv 我安装了 ruby 2.4.0 并将其设置为本地和全局。我可以在 .rbenv/versions 中看到它,但是当我检查我的 ruby 版本时,我仍然得到 2.0.0

$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

当我尝试安装 Rails 时,我得到以下信息;

$ gem install rails
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

我不确定如何在我的系统中使用 rbenv ruby 版本然后安装 rails。

您可能需要将 rbenv 添加到您的 ~/.bash_profile:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile  
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile 

然后来源:

source ~/.bash_profile

然后可以使用rbenv命令:

# install a Ruby version:
$ rbenv install <version>

# show versions currently installed and indicate current version
$ rbenv versions

# set ruby version for a specific dir
$ rbenv local <version>

# set ruby version globally
$ rbenv global <version>

# list all available versions:
$ rbenv install -l

rbenv命令用于安装、版本切换等