Mac安装配置ruby

1.  安装Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

 这里执行ruby命令没有问题,因为Mac OSX系统自带ruby。

2. 使用Homebrew安装ruby

Mac OSX默认带有ruby,但一般版本比较旧:

brew install ruby

完成之后输入以下指令可以看到安装的版本:

ruby -v

3.  gem安装rails

rails的安装命令

gem install rails --no-ri --no-rdoc

正常情况会提示错误(在天朝):

ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/rails-4.2.1.gemspec.rz)

 问题原因: https://rubygems.org 遭遇 GFW的屏蔽不能访问

解决方法:

把淘宝的gem server添加到source server,删除原有的server:https://rubygems.org

gem sources −−remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/

 查看source server

gem sources -l

 目前只有taobao的镜像server

*** CURRENT SOURCES ***

https://ruby.taobao.org/

参见:RubyGems 淘宝镜像 https://ruby.taobao.org/

安装rails:

gem install rails
可以看到rails的安装进程
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: activesupport-4.2.1.gem (100%)
Successfully installed activesupport-4.2.1
Fetching: rack-1.6.1.gem (100%)
Successfully installed rack-1.6.1
Fetching: rack-test-0.6.3.gem (100%)
Successfully installed rack-test-0.6.3
Fetching: mini_portile-0.6.2.gem (100%)
Successfully installed mini_portile-0.6.2

 4. 安装 rvm

curl -sSL https://get.rvm.io | bash -s stable

使安装的rvm生效

source /Users/jiangzhiqiang/.rvm/scripts/rvm

 5. 创建rails项目

rails new my_app --skip-bundle

 --skip-bundle 不运行bundle install, 因为bundle install 会从rubygems.org 下载文件,遭遇 GFW 屏蔽会访问出错。

相关推荐