本文介绍在Ubuntu 20.04系统上安装Ruby 2.7和Ruby 3.0.1编程语言的方法。它是一种动态的、开源的、面向对象的脚本语言,其创建时考虑到了简单性和生产力。当前在Ubuntu 20.04上安装Ruby主要有两种方法,一是使用Brightbox PPA存储库,二是使用RVM安装Ruby,当然,也可以用Rbenv。
从PPA存储库在Ubuntu 20.04上安装Ruby 2.7 Brightbox PPA存储库安装Ruby非常的方便,因为它使您可以灵活地安装他们维护和从包管理器更新的任何Ruby版本。 使用以下命令将PPA存储库添加到您的Ubuntu 20.04系统: sudo apt update sudo apt -y install software-properties-common sudo apt-add-repository ppa:brightbox/ruby-ng 参考:全面介绍Ubuntu系统中的PPA,包括使用PPA及删除的方法。 当被要求继续添加PPA存储库时,按<ENTER>键: Ubuntu packages for Ruby 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0 1.9.3 and 1.8. See https://www.brightbox.com/docs/ruby/ubuntu/ for more details. Discussion list here: https://groups.google.com/forum/#!forum/brightbox-ruby-ubuntu-packaging https://www.brightbox.com More info: https://launchpad.net/~brightbox/+archive/ubuntu/ruby-ng Press [ENTER] to continue or Ctrl-c to cancel adding it. Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease Get:2 http://mirrors.digitalocean.com/ubuntu focal InRelease [265 kB] Get:3 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu focal InRelease [23.8 kB] Hit:4 http://mirrors.digitalocean.com/ubuntu focal-updates InRelease Hit:5 http://mirrors.digitalocean.com/ubuntu focal-backports InRelease Get:6 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu focal/main amd64 Packages [4508 B] Get:7 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu focal/main Translation-en [2568 B] Fetched 296 kB in 1s (331 kB/s) Reading package lists... Done 添加repo后,更新您的包列表: sudo apt update 然后安装你想要的Ruby版本。对我来说,我正在安装Ruby 2.7,运行以下命令: $ sudo apt install ruby2.7 返回的信息如下: Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: fonts-lato javascript-common libjs-jquery libruby2.7 rake ruby-minitest ruby-net-telnet ruby-power-assert ruby-test-unit ruby-xmlrpc rubygems-integration unzip zip Suggested packages: apache2 | lighttpd | httpd bundler The following NEW packages will be installed: fonts-lato javascript-common libjs-jquery libruby2.7 rake ruby-minitest ruby-net-telnet ruby-power-assert ruby-test-unit ruby-xmlrpc ruby2.7 rubygems-integration unzip zip 0 upgraded, 14 newly installed, 0 to remove and 47 not upgraded. Need to get 7853 kB of archives. After this operation, 34.5 MB of additional disk space will be used. Do you want to continue? [Y/n] y Brightbox维护的Ruby包包括2.7、2.6、2.5、2.4、2.3、2.2、2.1、2.0、1.9.3和1.8。如果是安装Ruby 2.6,则示例如下: sudo apt install ruby2.6 安装后,检查版本: $ ruby --version ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux-gnu] 说明安装Ruby 2.7版本成功。
使用RVM在Ubuntu 20.04上安装Ruby 3.0.1 除了以上方法外,您还可以使用RVM安装Ruby。RVM是一个命令行工具,允许您轻松安装、管理和使用从解释器到gems的多个ruby环境。 导入RVM GPG密钥: sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 然后通过运行以下命令在Ubuntu 20.04上安装RVM: curl -L get.rvm.io | sudo bash -s stable source /etc/profile.d/rvm.sh 您可以检查版本: $ rvm --version rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io] 通过运行以下命令安装依赖项: # rvm requirements run Checking requirements for ubuntu. Installing requirements for ubuntu. Updating system.. Installing required packages: g++, gcc, autoconf, automake, bison, libc6-dev, libffi-dev, libgdbm-dev, libncurses5-dev, libsqlite3-dev, libtool, libyaml-dev, make, pkg-config, sqlite3, zlib1g-dev, libgmp-dev, libreadline-dev, libssl-dev.............................. Requirements installation successful. 像下面这样安装Ruby。您可以检查Ruby版本以获取版本号: # rvm install 3.0.1 Searching for binary rubies, this might take some time. Found remote file https://rubies.travis-ci.org/ubuntu/20.04/x86_64/ruby-3.0.1.tar.bz2 Checking requirements for ubuntu. Requirements installation successful. ruby-3.0.1 - #configure ruby-3.0.1 - #download
要列出可用的Ruby解释器,请使用: # rvm list known 确认Ruby版本: # ruby --version ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux] 说明安装Ruby 3.0.1版本成功。
相关主题 |