mac or linux 搭建ruby+rails

mac通常會(huì)自帶ruby一個(gè)版本的ruby環(huán)境, 比如我的是2.0.0。 如果項(xiàng)目需要的版本巧好和自己的默認(rèn)版本一樣,就不用折騰安裝其他版本了。 如果不一樣, 這里介紹使用rvm來安裝管理ruby版本

安裝 rvm(參照官網(wǎng)http://www.rvm.io/)

第一步可能不是必須的

第一步

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

第二步

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

成功之后通常會(huì)有個(gè)提示

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成功之后, 再倒數(shù)第二行有一個(gè)WARNING, 這時(shí)候如果直接運(yùn)行rvm 可能會(huì)出現(xiàn)command not found 解決方案: 運(yùn)行一下命令

source ~/.profile

此時(shí)再運(yùn)行: 類似一下結(jié)果表示安裝成功

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
  • 安裝一個(gè)ruby版本
rvm install 1.9.3

這里安裝了最新的1.9.3, rvm list known列表里面的都可以拿來安裝。

  • 使用一個(gè)ruby版本
rvm use 1.9.3
  • 設(shè)置為默認(rèn)版本
rvm use 1.9.3 --default 
  • 查詢已經(jīng)安裝的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 項(xiàng)目則在項(xiàng)目運(yùn)行 bundle install

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容