本文介绍如何在Ubuntu 18.04 LTS系统上安装Ruby,安装Ruby最简单方法是从PPA存储库中使用命令安装,我们使用的是Brightbox PPA存储库,它一直为Ubuntu提供优化的Ruby软件包。同时在Ubuntu 18.04上安装Ruby的其他方法有使用RVM安装Ruby、使用Rbenv安装Ruby等,参考使用rbenv安装和管理Ruby版本一文。
从PPA存储库安装Ruby的方法 我倾向于使用Brightbox PPA存储库,因为它可以灵活地安装他们维护的任何Ruby版本。 1、使用以下命令将PPA存储库添加到Ubuntu 18.04系统中: sudo apt -y install software-properties-common sudo apt-add-repository ppa:brightbox/ruby-ng 2、添加repo后,更新系统的包列表: sudo apt update 3、然后安装你想要的Ruby版本,比如我正在安装Ruby 2.5。 $ sudo apt install ruby2.5 Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic linux-image-4.15.0-29-generic linux-modules-4.15.0-29-generic linux-modules-extra-4.15.0-29-generic Use 'sudo apt autoremove' to remove them. The following packages will be upgraded: ruby2.5 1 upgraded, 0 newly installed, 0 to remove and 2 not upgraded. Need to get 56.6 kB of archives. After this operation, 2,048 B of additional disk space will be used. Get:1 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu bionic/main amd64 ruby2.5 amd64 2.5.3-1bbox1~bionic1 [56.6 kB] Fetched 56.6 kB in 1s (66.2 kB/s) (Reading database ... 141513 files and directories currently installed.) Preparing to unpack .../ruby2.5_2.5.3-1bbox1~bionic1_amd64.deb ... Unpacking ruby2.5 (2.5.3-1bbox1~bionic1) over (2.5.1-1ubuntu1.1) ... Setting up ruby2.5 (2.5.3-1bbox1~bionic1) ... update-alternatives: using /usr/bin/gem2.5 to provide /usr/bin/gem (gem) in auto mode update-alternatives: using /usr/bin/ruby2.5 to provide /usr/bin/ruby (ruby) in auto mode Processing triggers for man-db (2.8.3-2ubuntu0.1) ... 4、在Brightbox维护的Ruby包中有2.4,2.3,2.2,2.1,2.0,1.9.3和1.8.7版本,比如安装Ruby 2.4的示例,使用以下命令: sudo apt install ruby2.4 5、安装后,检查版本,运行以下命令: $ ruby --version 结果显示:ruby 2.5.1p57 [x86_64-linux-gnu] 至此,从PPA存储库安装Ruby成功了。
使用RVM安装Ruby的方法 可以使用RVM安装Ruby,RVM是一个命令行工具,允许你轻松地安装,管理和使用多个ruby环境。 1、导入RVM GPG密钥: sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 2、然后通过运行以下命令在Ubuntu 18.04系统上安装RVM: curl -L get.rvm.io | sudo bash -s stable source /etc/profile.d/rvm.sh 3、可以查看版本: $ rvm --version rvm 1.29.6 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin 4、通过运行命令安装依赖项: rvm requirements run 5、安装Ruby命令如下: # rvm install 2.5.1 Warning, new version of rvm available '1.29.7', you are using older version '1.29.6'. You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/18.04/x86_64/ruby-2.5.1.tar.bz2 Checking requirements for ubuntu. Requirements installation successful. ruby-2.5.1 - #configure ruby-2.5.1 - #download ruby-2.5.1 - #validate archive ruby-2.5.1 - #extract ruby-2.5.1 - #validate binary ruby-2.5.1 - #setup ruby-2.5.1 - #gemset created /usr/local/rvm/gems/ruby-2.5.1@global ruby-2.5.1 - #importing gemset /usr/local/rvm/gemsets/global.gems............. ruby-2.5.1 - #generating global wrappers....... ruby-2.5.1 - #gemset created /usr/local/rvm/gems/ruby-2.5.1 ruby-2.5.1 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.5.1 - #generating default wrappers....... 6、要列出可用的Ruby,请使用: rvm list known 至此,使用RVM安装Ruby成功了。
相关主题 |