zoukankan      html  css  js  c++  java
  • Ubuntu下安装 Ruby, Rails 运行环境

    说明:

    在安装之前我做了:1、更新软件源,详细指导在这里

             2、更新系统:sudo apt-get update && sudo apt-get upgrade;

             3、安装fcitx,安装sogou输入法;

             4、打字不方便,禁用触摸板:sh TouchPad.sh off

    接着就开始安装了!这里说明一下,后面的可能有几步可能是多余的,怕出错,就没有说去更正简化。

    参考资料来自:边晓宇@CSDNruby-china.org如何快速正确的安装 Ruby, Rails 运行环境

      操作系统Ubuntu 14.04.1

    一、安装后面需要使用curl,用dpkg -s curl命令检查一下系统中有没有安装:

    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) 来列出它们的内容。

    提示没有安装,然后安装:

    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>

    二、安装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:~$ 

    三、安装Ruby

    1、首先先将源定位到淘宝的Ruby镜像里

    sed -i 's!cache.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db

    2、先解决依赖,安装依赖程序,至于解释,边晓宇@CSDN博客里是这么解释的:

    通过rvm requirements命令,可以察看安装各版本时候的前提条件。其中这句是需要关注的。这是安装依赖的第三方包,没有这个安装不成功岂不是很悲剧?
    rvm requirements && rvm pkg install readline

    3、安装特定版本的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相关的设置。

    四、安装rails

    1、查看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

    2、安装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

    五、其他扩展

    1、gem命令是管理rubyGem包的,如果有需要可以查看帮助怎么使用;

    2、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

    命令。

  • 相关阅读:
    推荐系统和业务系统对比:
    认识事物的过程是:
    思考:面向对象源码的解析和阅读需要注意和把握的点
    推荐系统中ES使用过程中遇到的问题:
    使用缓存功能要掌握住(心里有数)的点:
    思考:延迟决策是非常重要的
    压力测试中tps上不去的原因
    mysql 高级查询二
    mysql 高级查询
    fiddler设置https抓包
  • 原文地址:https://www.cnblogs.com/ufindme/p/4093597.html
Copyright © 2011-2022 走看看