Linux 是一套免费使用和自由传播的类 Unix 操作系统, 是一个基于 POSIX 和 UNIX 的多用户多任务支持多线程和多 CPU 的操作系统它能运行主要的 UNIX 工具软件应用程序和网络协议
mac 通常会自带 ruby 一个版本的 ruby 环境, 比如我的是 2.0.0 如果项目需要的版本巧好和自己的默认版本一样, 就不用折腾安装其他版本了 如果不一样, 这里介绍使用 rvm 来安装管理 ruby 版本
安装 rvm(参照官网 http://www.rvm.io/)
第一步可能不是必须的
第一步
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
第二步
curl -sSL https://get.rvm.io | bash -s stable
成功之后通常会有个提示
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc', but no GPG software exists to validate it, skipping. Installing RVM to /Users/echen1/.rvm/ Adding rvm PATH line to /Users/echen1/.profile /Users/echen1/.mkshrc /Users/echen1/.bashrc /Users/echen1/.zshrc. Adding rvm loading line to /Users/echen1/.profile /Users/echen1/.bash_profile /Users/echen1/.zlogin. Installation of RVM in /Users/echen1/.rvm/ is almost complete: * To start using RVM you need to run `source /Users/echen1/.rvm/scripts/rvm` in all your open shell windows, in rare cases you need to reopen all shell windows. * WARNING: '~/.profile' file found. To load it into your shell, add the following line to '/Users/echen1/.bash_profile':
如上面安装 rvm 成功之后, 再倒数第二行有一个 WARNING, 这时候如果直接运行 rvm 可能会出现 command not found 解决方案: 运行一下命令
source ~/.profile
此时再运行: 类似一下结果表示安装成功
rvm -v
image.png 切换源
原生的源在国外, 通常比较慢, 所以可以切换到淘宝源 (参考: https://ruby.taobao.org/)
- For mac
- sed - i.bak - E 's!https?://cache.ruby-lang.org/pub/ruby!https://ruby.taobao.org/mirrors/ruby!'$rvm_path / config / db
- For Linux
- sed - i - E 's!https?://cache.ruby-lang.org/pub/ruby!https://ruby.taobao.org/mirrors/ruby!'$rvm_path / config / db
rvm 使用介绍 列出已知的 ruby 版本 rvm list known 安装一个 ruby 版本 rvm install 1.9.3
这里安装了最新的 1.9.3, rvm list known 列表里面的都可以拿来安装
使用一个 ruby 版本
rvm use 1.9.3 设置为默认版本
rvm use 1.9.3 --default
查询已经安装的 ruby rvm list 切换 gem 源
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -l
image.png
如图表示切换成功
安装 rails 方法 1(直接安装)
gem install rails 方法 2
如果已有 rails 项目则在项目运行 bundle install
来源: http://www.phperz.com/article/18/0215/360811.html