RVM Install
rvm:Ruby Version Manager
,是ruby
的版本管理器,包括ruby
的版本管理和gem
库管理(gemset
),它允许多个ruby
版本存在。
rvm
安装
安装完需要载入rvm
环境
1
| source ~/.rvm/scripts/rvm
|
Ruby Install
rvm安装ruby一条指令就可以了rvm install [rubyversion]
,安装前看看目前ruby有哪些版本可以安装:
1 2 3 4 5 6 7 8 9 10 11 12 13
| Huug$ rvm list known # MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-head] # security released on head [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p330] [ruby-]1.9.3[-p551] [ruby-]2.0.0[-p648] [ruby-]2.1[.8] [ruby-]2.2[.4] [ruby-]2.3[.0] [ruby-]2.2-head ruby-head
|
选择安装2.3版本
用rvm
安装ruby
等待漫长时间后返回
1 2
| ... ... requirements installation failed with status :1.
|
以下是fail的详细信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Searching for binary rubies, this might take some time. No binary rubies available for: osx/10.10/x86_64/ruby-2.3.0. Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies. Checking requirements for osx. Installing requirements for osx. Updating system....... Error running 'requirements_osx_brew_update_system ruby-2.3.0', showing last 15 lines of /Users/hanhuanming/.rvm/log/1472866957_ruby-2.3.0/update_system.log https://github.com/Homebrew/homebrew/wiki/Common-Issues and make sure `brew update` works before continuing.' ++ rvm_pretty_print stderr ++ case "${rvm_pretty_print_flag:=auto}" in ++ case "${TERM:-dumb}" in ++ case "$1" in ++ [[ -t 2 ]] ++ return 1 ++ printf %b 'Failed to update Homebrew, follow instructions here: https://github.com/Homebrew/homebrew/wiki/Common-Issues and make sure `brew update` works before continuing.\n' Failed to update Homebrew, follow instructions here: https://github.com/Homebrew/homebrew/wiki/Common-Issues and make sure `brew update` works before continuing. ++ return 1 Requirements installation failed with status: 1.
|
从fail信息中看到Failed to update Homebrew
,单独敲了brew update
发现等待许久后仍无任何反应,google了一下在stackoverflow上有人解释rvm安装Homebrew可能存在问题,需要重新安装Homebrew。
安装Homebrew指令如下:
1
| ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
输入该指令后,提示已经存在Homebrew,安装失败。
1 2
| -e:81: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777 It appears Homebrew is already installed.
|
根据提示,卸载Homebrew
1
| ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
|
成功卸载后再用刚才的指令安装Homebrew,出现以下输出表示安装成功。
1
| ==> Installation successful!
|
重新安装Homebrew后,单独执行rvm requirements
来检查和安装所需运行环境,发现可以正常check和install所需的依赖环境。
1 2 3 4 5 6 7 8 9
| Checking requirements for osx. Installing requirements for osx. Updating system..... Installing required custom packages: homebrew/versions . Installing required packages: autoconf, automake, libtool, pkg-config, gcc49, libyaml, readline, libksba, openssl............... ... ... Requirements installation successful.
|
安装完依赖环境后,安装ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 13.5M 100 13.5M 0 0 10294 0 0:22:58 0:22:58 --:--:-- 9241 ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - Installed rubygems 2.5.1 is newer than 2.4.8 provided with installed ruby, skipping installation, use --force to force installation. ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - ruby-2.3.0 - Install of ruby-2.3.0 -
|
在经过一段时间后,终于安装成功。验证下是否安装成功,可以通过ruby -v
来查看版本是否安装版本:
1 2
| huug$ ruby -v ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
|
貌似还是系统默认的版本,通过rvm use 2.3.0 --default
选择默认版本为2.3.0。
1 2 3 4
| hugg$ rvm use 2.3.0 --default Using /Users/huug/.rvm/gems/ruby-2.3.0 huug$ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14]
|
到这里ruby就安装好了,接下来安装rails。
Rails Install
先来了解下gem
,gem
是一个管理Ruby
库和程序的标准包,而用来管理项目的gem
的,叫bundler
。
由于你懂的原因,需要换一下gem
源:
1 2 3
| hugg$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ https://gems.ruby-china.org/ added to sources https://rubygems.org/ removed from sources
|
还需要安装bundler
:
1 2 3 4 5 6 7
| huug$ gem install bundler Fetching: bundler-1.12.5.gem (100%) Successfully installed bundler-1.12.5 Parsing documentation for bundler-1.12.5 Installing ri documentation for bundler-1.12.5 Done installing documentation for bundler after 3 seconds 1 gem installed
|
现在可以正式安装rails了:
再输出一屏幕的Fetching
和Successfully
后,rails安装完毕,来看一下rails版本:
1 2
| huug$ rails -v Rails 5.0.0.1
|
接下来就动手欣赏ruby on rails
之美吧。
更多Ruby on Rails信息可参见Ruby China