如何在Linux上安装Ruby

Ruby is installed on most Linux distributions by default. However, you can follow the steps below to determine if Ruby is installed and, if not, install the Ruby interpreter on your Linux computer.

默认情况下, Ruby已安装在大多数Linux发行版上。 但是,您可以按照以下步骤确定是否已安装Ruby,如果尚未安装,请在Linux计算机上安装Ruby解释器。

如何在Linux上安装Ruby ( How to Install Ruby on Linux )

For an Ubuntu-based distribution, follow the following procedure to verify whether you have Ruby installed, and if not, to install it.

对于基于Ubuntu的发行版,请遵循以下过程来验证是否已安装Ruby,如果尚未安装,则进行安装。

  1. Open a terminal window. One way open the terminal window (sometimes called a "shell" or "bash shell") is to select Applications > Accessories > Terminal.

    打开一个终端窗口。 打开终端窗口(有时称为“外壳”或“ bash外壳”)的一种方法是选择“ 应用程序” >“ 附件” >“ 终端”

  2. Run the command which ruby. If you see a path such as /usr/bin/ruby, Ruby is installed. If you don't see any response or get an error message, Ruby is not installed.

    运行命令ruby 。 如果看到诸如/ usr / bin / ruby​​之类的路径,则说明已安装Ruby。 如果您没有看到任何响应或收到错误消息,则说明未安装Ruby。

  3. To verify that you have a current version of Ruby, run the command ruby -v.

    要验证您是否具有当前版本的Ruby,请运行命令ruby -v

  4. Compare the version number returned with the version number on the Ruby download page.

    将返回的版本号与Ruby下载页面上的版本号进行比较。

    These numbers don't have to be exact, but if you are running a version that's too old, some of the features may not work correctly.

    这些数字不一定准确,但是如果您运行的版本太旧,则某些功能可能无法正常使用。

  5. Install appropriate Ruby packages. This process differs between distributions, but on Ubuntu run the following command:

    安装适当的Ruby软件包。 此过程在发行之间有所不同,但是在Ubuntu上运行以下命令:

    Install appropriate Ruby packages. This process differs between distributions, but on Ubuntu run the following command:

    安装适当的Ruby软件包。 此过程在发行之间有所不同,但是在Ubuntu上运行以下命令:

    sudo apt-get install ruby-full

验证Ruby是否正常工作 ( Verify That Ruby Works Correctly )

Open a text editor and save the following as test.rb.

打开一个文本编辑器,并将以下内容保存为test.rb。


#!/usr/bin/env ruby
puts "Hello world!"

In the terminal window, change directory to the directory where you saved test.rb. Run the command

在终端窗口中,将目录更改为保存test.rb的目录。 运行命令

chmod +x test.rb, then run the command 
./test.rb

You should see the message Hello world! displayed if Ruby is installed correctly.

Tips:

  1. Every distribution is different. Refer to your distribution's documentation and community forums for help installing Ruby on distributions other than Ubuntu or its variants.
  2. For distributions other than Ubuntu, if your distribution doesn't provide a tool like apt-get then you can use a site such as RPMFind to find Ruby packages. Look for the irb, ri and rdoc packages as well, but depending on how the RPM package was built, it may already include these programs.

翻译自: https://www.thoughtco.com/instal-ruby-on-linux-2908370

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值