說明:html
在安裝以前我作了:一、更新軟件源,詳細指導在這裏;java
二、更新系統:sudo apt-get update && sudo apt-get upgrade;linux
三、安裝fcitx,安裝sogou輸入法;git
四、打字不方便,禁用觸摸板:sh TouchPad.sh offgithub
接着就開始安裝了!這裏說明一下,後面的可能有幾步多是多餘的,怕出錯,就沒有說去更正簡化。web
參考資料來自:邊曉宇@CSDN 和 ruby-china.org如何快速正確的安裝 Ruby, Rails 運行環境shell
操做系統Ubuntu 14.04.1數據庫
1、安裝後面須要使用curl,用dpkg -s curl命令檢查一下系統中有沒有安裝:ubuntu
zhaomh@ZHAO:~$ dpkg -s curl dpkg-query: package 'curl' is not installed and no information is available 使用 dpkg --info (= dpkg-deb --info) 來檢測打包好的文件, 還能夠經過 dpkg --contents (= dpkg-deb --contents) 來列出它們的內容。
提示沒有安裝,而後安裝:windows
zhaomh@ZHAO:~$ sudo dpkg -s curl dpkg-query: package 'curl' is not installed and no information is available 使用 dpkg --info (= dpkg-deb --info) 來檢測打包好的文件, 還能夠經過 dpkg --contents (= dpkg-deb --contents) 來列出它們的內容。 zhaomh@ZHAO:~$ sudo apt-get install curl 正在讀取軟件包列表... 完成 正在分析軟件包的依賴關係樹 正在讀取狀態信息... 完成 下列軟件包是自動安裝的而且如今不須要了: linux-headers-generic linux-image-generic Use 'apt-get autoremove' to remove them. 下列【新】軟件包將被安裝: curl 升級了 0 個軟件包,新安裝了 1 個軟件包,要卸載 0 個軟件包,有 0 個軟件包未被升級。 須要下載 123 kB 的軟件包。 解壓縮後會消耗掉 313 kB 的額外空間。 獲取:1 http://mirrors.ustc.edu.cn/ubuntu/ trusty-security/main curl amd64 7.35.0-1ubuntu2.2 [123 kB] 下載 123 kB,耗時 0秒 (411 kB/s) Selecting previously unselected package curl. (正在讀取數據庫 ... 系統當前共安裝有 197612 個文件和目錄。) Preparing to unpack .../curl_7.35.0-1ubuntu2.2_amd64.deb ... Unpacking curl (7.35.0-1ubuntu2.2) ... Processing triggers for man-db (2.6.7.1-1ubuntu1) ... 正在設置 curl (7.35.0-1ubuntu2.2) ...
測試一下:
zhaomh@ZHAO:~$ dpkg -s curl Package: curl Status: install ok installed Priority: optional Section: web Installed-Size: 306 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Architecture: amd64 Multi-Arch: foreign Version: 7.35.0-1ubuntu2.2 Depends: libc6 (>= 2.17), libcurl3 (= 7.35.0-1ubuntu2.2), zlib1g (>= 1:1.1.4) Description: command line tool for transferring data with URL syntax curl is a command line tool for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP. . curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks. Homepage: http://curl.haxx.se Original-Maintainer: Alessandro Ghedini <ghedo@debian.org>
2、安裝rvm
用rvm官方推薦的方式安裝:curl -L get.rvm.io | bash -s stable
zhaomh@ZHAO:~$ curl -L get.rvm.io | bash -s stable % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 184 100 184 0 0 71 0 0:00:02 0:00:02 --:--:-- 71 100 22686 100 22686 0 0 6852 0 0:00:03 0:00:03 --:--:-- 0 Downloading https://github.com/wayneeseguin/rvm/archive/1.26.1.tar.gz Downloading https://github.com/wayneeseguin/rvm/releases/download/1.26.1/1.26.1.tar.gz.asc gpg: 已建立目錄‘/home/zhaomh/.gnupg’ gpg: 新的配置文件‘/home/zhaomh/.gnupg/gpg.conf’已創建 gpg: 警告:在‘/home/zhaomh/.gnupg/gpg.conf’裏的選項於這次運行期間未被使用 gpg: 鑰匙環‘/home/zhaomh/.gnupg/pubring.gpg’已創建 gpg: 於 2014年11月12日 星期三 05時23分59秒 CST 建立的簽名,使用 RSA,鑰匙號 BF04FF17 gpg: 沒法檢查簽名:找不到公鑰 Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures). GPG signature verification failed for '/home/zhaomh/.rvm/archives/rvm-1.26.1.tgz' - 'https://github.com/wayneeseguin/rvm/releases/download/1.26.1/1.26.1.tar.gz.asc'! try downloading the signatures: gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 or if it fails: command curl -sSL https://rvm.io/mpapis.asc | gpg --import - the key can be compared with: https://rvm.io/mpapis.asc https://keybase.io/mpapis
安裝失敗,而後按照提示看,前面的都看不懂,只認識一個單詞是幹嗎的,而後:
curl -sSL https://rvm.io/mpapis.asc | gpg --import
接着輸入上面的安裝RVM的命令:
zhaomh@ZHAO:~$ curl -L get.rvm.io | bash -s stable % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 184 100 184 0 0 76 0 0:00:02 0:00:02 --:--:-- 76 100 22686 100 22686 0 0 6767 0 0:00:03 0:00:03 --:--:-- 307k Downloading https://github.com/wayneeseguin/rvm/archive/1.26.1.tar.gz Downloading https://github.com/wayneeseguin/rvm/releases/download/1.26.1/1.26.1.tar.gz.asc gpg: 於 2014年11月12日 星期三 05時23分59秒 CST 建立的簽名,使用 RSA,鑰匙號 BF04FF17 gpg: 無缺的簽名,來自於「Michal Papis (RVM signing) <mpapis@gmail.com>」 gpg: 警告:這把密鑰未經受信任的簽名認證! gpg: 沒有證據代表這個簽名屬於它所聲稱的持有者。 主鑰指紋: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3 子鑰指紋: 62C9 E5F4 DA30 0D94 AC36 166B E206 C29F BF04 FF17 GPG verified '/home/zhaomh/.rvm/archives/rvm-1.26.1.tgz' Installing RVM to /home/zhaomh/.rvm/ Adding rvm PATH line to /home/zhaomh/.profile /home/zhaomh/.bashrc /home/zhaomh/.zshrc. RVM sourcing line found in /home/zhaomh/.bashrc. RVM sourcing line not found for Zsh, rerun this command with '--auto-dotfiles' flag to fix it. Installation of RVM in /home/zhaomh/.rvm/ is almost complete: * To start using RVM you need to run `source /home/zhaomh/.rvm/scripts/rvm` in all your open shell windows, in rare cases you need to reopen all shell windows. # zhaomh, # # Thank you for using RVM! # We sincerely hope that RVM helps to make your life easier and more enjoyable!!! # # ~Wayne, Michal & team. In case of problems: http://rvm.io/help and https://twitter.com/rvm_io
查看版本:
zhaomh@ZHAO:~$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc zhaomh@ZHAO:~$ source ~/.bashrc zhaomh@ZHAO:~$ rvm -v rvm 1.26.1 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/] zhaomh@ZHAO:~$
3、安裝Ruby
一、首先先將源定位到淘寶的Ruby鏡像裏
sed -i 's!cache.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db
二、先解決依賴,安裝依賴程序,至於解釋,邊曉宇@CSDN博客裏是這麼解釋的:
經過rvm requirements命令,能夠察看安裝各版本時候的前提條件。其中這句是須要關注的。這是安裝依賴的第三方包,沒有這個安裝不成功豈不是很悲劇?
rvm requirements && rvm pkg install readline
三、安裝特定版本的ruby
zhaomh@ZHAO:~$ 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[-p550] [ruby-]2.0.0-p576 [ruby-]2.0.0[-p594] [ruby-]2.1.3 [ruby-]2.1[.4] [ruby-]2.1-head ruby-head # for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.1 # JRuby jruby-1.6.8 jruby[-1.7.16.1] jruby-head # Rubinius rbx-1.3.3 rbx-2.0.0 rbx-2.1.1 rbx[-2.2.10] rbx-head # Opal opal # Minimalistic ruby implementation - ISO 30170:2012 mruby[-head] # Ruby Enterprise Edition ree-1.8.6 ree[-1.8.7][-2012.02] # GoRuby goruby # Topaz topaz # MagLev maglev[-head] maglev-1.0.0 # Mac OS X Snow Leopard Or Newer macruby-0.10 macruby-0.11 macruby[-0.12] macruby-nightly macruby-head # IronRuby ironruby[-1.1.3] ironruby-head zhaomh@ZHAO:~$ rvm install 2.1.3 Searching for binary rubies, this might take some time. Found remote file https://rvm.io/binaries/ubuntu/14.04/x86_64/ruby-2.1.3.tar.bz2 Checking requirements for ubuntu. Requirements installation successful. ruby-2.1.3 - #configure ruby-2.1.3 - #download ** Resuming transfer from byte position 4845568 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 18.3M 100 18.3M 0 0 142k 0 0:02:11 0:02:11 --:--:-- 161k ruby-2.1.3 - #validate archive ruby-2.1.3 - #extract ruby-2.1.3 - #validate binary ruby-2.1.3 - #setup ruby-2.1.3 - #gemset created /home/zhaomh/.rvm/gems/ruby-2.1.3@global ruby-2.1.3 - #importing gemset /home/zhaomh/.rvm/gemsets/global.gems.......................................... ruby-2.1.3 - #generating global wrappers........ ruby-2.1.3 - #gemset created /home/zhaomh/.rvm/gems/ruby-2.1.3 ruby-2.1.3 - #importing gemsetfile /home/zhaomh/.rvm/gemsets/default.gems evaluated to empty gem list ruby-2.1.3 - #generating default wrappers........ zhaomh@ZHAO:~$ ruby -v ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux] zhaomh@ZHAO:~$ rvm use 2.1.2 --default ruby-2.1.2 is not installed. To install do: 'rvm install ruby-2.1.2' zhaomh@ZHAO:~$ rvm use 2.1.3 --default Using /home/zhaomh/.rvm/gems/ruby-2.1.3 zhaomh@ZHAO:~$ rvm -v rvm 1.26.1 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/] zhaomh@ZHAO:~$ ruby -v ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
若是想UNDO上面的版本默認設置能夠
zhaomh@ZHAO:~$rvm reset
或者
zhaomh@ZHAO:~$ rvm --help | grep default
抓取與default相關的設置。
4、安裝rails
一、查看gem,並更換gem源爲淘寶鏡像
zhaomh@ZHAO:~$ gem -v 2.2.2 zhaomh@ZHAO:~$ gem source *** CURRENT SOURCES *** https://rubygems.org/ zhaomh@ZHAO:~$ gem source -r https://rubygems.org/ https://rubygems.org/ removed from sources zhaomh@ZHAO:~$ gem source -a https://ruby.taobao.org https://ruby.taobao.org added to sources zhaomh@ZHAO:~$ gem source *** CURRENT SOURCES *** https://ruby.taobao.org
二、安裝Rails
zhaomh@ZHAO:~$ gem install rails Fetching: thread_safe-0.3.4.gem (100%) Successfully installed thread_safe-0.3.4 Fetching: minitest-5.4.3.gem (100%) Successfully installed minitest-5.4.3 ......(省略) Parsing documentation for rails-4.1.7 Installing ri documentation for rails-4.1.7 Parsing documentation for railties-4.1.7 Installing ri documentation for railties-4.1.7 Parsing documentation for sprockets-3.0.0.beta.3 Installing ri documentation for sprockets-3.0.0.beta.3 Parsing documentation for sprockets-rails-2.2.0 Installing ri documentation for sprockets-rails-2.2.0 Parsing documentation for thor-0.19.1 Installing ri documentation for thor-0.19.1 Parsing documentation for thread_safe-0.3.4 Installing ri documentation for thread_safe-0.3.4 Parsing documentation for tzinfo-1.2.2 Installing ri documentation for tzinfo-1.2.2 Done installing documentation for actionmailer, actionpack, actionview, activemodel, activerecord, activesupport, arel, builder, erubis, i18n, mail, mime-types, minitest, rack, rack-test, rails, railties, sprockets, sprockets-rails, thor, thread_safe, tzinfo after 504 seconds 22 gems installed
假如想安裝特定的版本的話:好比我想要安裝Rails-4.1.6版本的話(我安裝時4.1.7剛出來)
gem install rails --version=4.1.6
5、其餘擴展
一、gem命令是管理rubyGem包的,若是有須要能夠查看幫助怎麼使用;
二、RVM(ruby version manager)是用來管理ruby版本的工具,可是能夠藉助RVM來切換ruby 的版本(參考來源)
rvm use 2.1.2
而且綁定特定的Rail的版本(這要注意版本支不支持rails)
rvm use2.1.2@rails4.1.6
這個話,最好參考RVM的命令幫助,由於不排除版本緣由會更換命令形式。
可是綁定以後可能再次單獨調用Rail會找不到,好比
rails -v
命令。