mac ruby 环境变量_Ruby环境设置| 在Mac和Windows操作系统上安装Ruby

mac ruby 环境变量

Ruby环境设置 (Ruby Environment Setup)

1)在Mac操作系统上安装Ruby (1) Installation of Ruby on Mac Operating System)

Ruby is already included in default macOS installation but it won't be the latest version. In the following steps, we are setting up Ruby Programming Environment using Homebrew. You will have to use the Terminal Application provided macOS.

Ruby已包含在默认的macOS安装中,但它不是最新版本。 在以下步骤中,我们将使用Homebrew设置Ruby编程环境 。 您将必须使用终端应用程序提供的macOS。

Step 1:

第1步:

Install Xcode(An IDE) Command line tool. Though it is not required for writing Ruby programs, Ruby and some of its components will depend upon Xcode's Command Line Tools package. Execute the command given below in the Terminal and these components will be downloaded and installed,

安装Xcode(IDE)命令行工具。 尽管不需要编写Ruby程序,但Ruby及其某些组件将取决于Xcode的Command Line Tools软件包。 在终端中执行下面给出的命令,这些组件将被下载并安装,

 $ xcode-select –install

A prompt will appear to start the installation. Accept the software license and then tools will be downloaded and installed automatically.

出现提示,开始安装。 接受软件许可证,然后将自动下载并安装工具。

Step 2:

第2步:

Install and Set up Homebrew. After installing Xcode, you are ready to install Homebrew (It is a package manager). We will use Homebrew to install the latest version of Ruby and configure our system to use this latest version. Type the following command in the Terminal to install Homebrew.

安装和设置Homebrew。 安装Xcode之后,您就可以安装Homebrew(它是一个程序包管理器)。 我们将使用Homebrew安装最新版本的Ruby,并将我们的系统配置为使用该最新版本。 在终端中键入以下命令以安装Homebrew。

 /usr/bin/ruby -e 

$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)

$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)

The script which is downloaded by curl will be executed by default Ruby interpreter. The homebrew installation process will be started. The password prompt will appear. Return to the Terminal by pressing 'Return' key once you've entered your password.

curl下载的脚本将在默认的Ruby解释器中执行。 自制程序安装过程将开始。 出现密码提示。 输入密码后,按“返回”键返回终端。

Press y for Yes, whenever you are required to confirm the installation process. After the installation of Homebrew, we will put the directory Homebrew uses to store its executable files at the front of the PATH environment variables.

在需要确认安装过程时,请按y表示是 。 安装Homebrew之后,我们将把Homebrew用于存储其可执行文件的目录放在PATH环境变量的前面。

Use the nano text editor to create the bash_profile file by typing the following command:

使用nano文本编辑器通过键入以下命令来创建bash_profile文件:

 $ nano ~/.bash_profile

Now add Homebrew's executable directory in front of the PATH

现在在PATH的前面添加Homebrew的可执行目录

 export PATH=/usr/local/bin:$PATH

To save the changes, use ctrl+O. A prompt will appear, press the Return key then press ctrl+X to exit the editor.

要保存更改,请使用ctrl + O。 出现提示,按Return键,然后按ctrl + X退出编辑器。

Now activate these changes by typing,

现在,通过键入来激活这些更改,

 $ source ~/.bash_profile

To verify the brew set up, execute the command,

要验证冲煮设置,请执行以下命令,

 $ brew doctor

You will see this in your terminal,
"Your system is ready to use brew."

您会在终端中看到这一点,
“您的系统已准备就绪,可以使用Brew。”

Step 3:

第三步:

Installing Ruby. In Homebrew, find packages related to Ruby by executing the following command,

安装Ruby。 在Homebrew中,通过执行以下命令查找与Ruby相关的软件包,

 $ brew search ruby

You will find a variety of options but don't get confused, just ask brew to install ruby by typing.

您会找到多种选择,但不要感到困惑,只需要求brew通过键入来安装ruby。

 $ brew install ruby

Homebrew will install many dependencies and ultimately install and download Ruby.

Homebrew将安装许多依赖项,并最终安装和下载Ruby。

To check the version installed, type:

要检查安装的版本,请键入:

 $ ruby -v

2)在Windows上安装Ruby (2) Installation of Ruby on Windows)

Follow the steps mentioned below for setting up Ruby Environment on your Windows PC,

请按照下面提到的步骤在Windows PC上设置Ruby Environment

Step 1: Download the zipped installer for Ruby Version 2.5.1 from the link provided https://rubyinstaller.org/downloads/.

第1步:从https://rubyinstaller.org/downloads/提供的链接下载Ruby版本2.5.1的压缩安装程序。

Step 2: You will get a zipped file, unpack it into a new directory or folder.

步骤2:您将获得一个压缩文件,将其解压缩到新目录或文件夹中。

Step 3: Now, Double Click on Ruby2.5.1.exe file. The installer window will appear.

步骤3:现在,双击Ruby2.5.1.exe文件。 将出现安装程序窗口。

Step 4: Click on the 'Next' and go through the documentation listed.

步骤4:点击“下一步”,然后浏览列出的文档。

Step 4: Keep Clicking on 'Next' until the installation process is not completed.

步骤4:继续单击“下一步”,直到安装过程完成。

Step 5: If you want to make sure that Ruby is working fine, then proceed with checking the version by typing '-v' in the Command Prompt with Ruby.

步骤5:如果要确保Ruby正常运行,请在Ruby的命令提示符中键入“ -v”以继续检查版本。

mac ruby 环境变量_Ruby环境设置| 在Mac和Windows操作系统上安装Ruby_第1张图片

Now open Notepad, write a ruby code and save it with ".rb" extension

现在打开记事本,编写一个ruby代码,并以“ .rb”扩展名保存

x = 190

if x > 2
	puts "x is greater than 2"
else
	puts "I can't guess the number"
end

Run the code through Ruby Command Prompt by writing "Ruby .rb" in the following way, you will get the output in the Command Prompt.

通过以以下方式编写“ Ruby .rb” ,通过Ruby Command Prompt运行代码,您将在Command Prompt中获得输出。

x is greater than 2

交互式Ruby(IRB) (Interactive Ruby (IRB))

  • As the word Interactive suggests, Interactive Ruby is inclined towards creating a more user-friendly environment through an Interactive Command line argument. Interactive Ruby was designed by Keiju Ishitsuka.

    就像Interactive这个词所暗示的那样,Interactive Ruby倾向于通过Interactive Command Line参数创建一个更加用户友好的环境。 Interactive Ruby由Keiju Ishitsuka设计。

  • It is a type of tool which is used to implement the Ruby expressions read from the conventional input. Ruby is an Object-Oriented Scripting language and Read-Eval-Print-Loop(REPL) programming in ruby is carried out through Interactive Ruby.

    它是一种工具,用于实现从常规输入中读取的Ruby表达式。 Ruby是一种面向对象的脚本语言,Ruby中的Read-Eval-Print-Loop(REPL)编程是通过Interactive Ruby进行的。

  • The commands are executed with an immediate response. Job control, line editing capabilities and command history are supported by IRB.

    这些命令将立即响应执行。 IRB支持作业控制,行编辑功能和命令历史记录。

  • IRB can be invoked through typing irb on the shell or on the command prompt in the following way:

    可以通过以下方法在外壳或命令提示符上键入irb来调用IRB:

You can quit Interactive Ruby anytime by typing "exit" or "quit" on the command prompt as shown below:

您可以随时通过在命令提示符下键入“退出”“退出”来退出Interactive Ruby,如下所示:

    irb(main):001:0> exit
        or
    irb(main):001:0> quit

Syntax:

句法:

 irb.rb [options] [programfile] [arguments]

Here is the list of Command-line options which you may need while working on Interactive Ruby Shell.

这是在Interactive Ruby Shell上工作时可能需要的命令行选项列表

Serial Number Option Description
1 v, --version Used for printing the version of irb.
2 -f Used for Supressing read of ~/.irbrc
3 -m Bash Calculator(bc) mode. It loads math, fraction or matrix are available.
4 -d Used for setting $DEBUG to true(same as 'ruby -d')
5 -l path Used for Specifying $LOAD_PATH directory
6 -r load-module Functioning is same as 'ruby -r'
7 -U Functioning is same as 'ruby -U'
8 -E enc Functioning is same as 'ruby -E'
9 -w Functioning is same as 'ruby -w'
10 -W[level=2] Functioning is same as 'ruby -W'
11 --inspect Use this option for output(default expect for bc mode)
12 --noninspect Don't use this option for output.
13 --readline Use readline extension module.
14 --prompt prompt-mode
--prompt-mode prompt-mode
Used for switching prompt mode. Pre-defined prompt modes are 'default', 'simple', 'xmp' and 'inf-ruby'
15 --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs. Suppresses--readline.
16 --simple-prompt It is a simple prompt mode
17 --noprompt No prompt mode.
18 --tracer It is used for displaying each execution of commands.
19 --back-trace-limit n Its default value is 16 and used for displaying back trace top n and tail n.
20 --irb_debug n It sets internal debug level to n(not for wide use)
序列号 选项 描述
1个 v --version 用于打印irb版本。
2 -F 用于禁止读取〜/ .irbrc
3 -米 Bash Calculator(bc)模式。 它可以加载数学,分数或矩阵。
4 -d 用于将$ DEBUG设置为true(与'ruby -d'相同)
5 -l路径 用于指定$ LOAD_PATH目录
6 -r加载模块 功能与“ ruby​​ -r”相同
7 -U 功能与“ ruby​​ -U”相同
8 -E enc 功能与“ ruby​​ -E”相同
9 -w 功能与“ ruby​​ -w”相同
10 -W [level = 2] 功能与“ ruby​​ -W”相同
11 - 检查 使用此选项进行输出(默认为bc模式)
12 -非检查 不要将此选项用于输出。
13 --readline 使用readline扩展模块。
14 -提示提示模式
-提示模式提示模式
用于切换提示模式。 预定义的提示模式为“默认”,“简单”,“ xmp”和“ inf-ruby”
15 --inf-ruby-mode 在emacs上使用适合于inf-ruby-mode的提示。 禁止-阅读线。
16 -简单提示 这是一个简单的提示模式
17 -无提示 没有提示模式。
18 -示踪剂 它用于显示命令的每次执行。
19 --back-trace-limit n 它的默认值是16,用于显示后跟踪top n和tail n。
20 --irb_debug n 它将内部调试级别设置为n(不广泛使用)

IRB can be used for evaluating a variety of expressions. You can go through the example given below for a better understanding of how Interactive Ruby evaluates expressions.

IRB可用于评估各种表达式。 您可以阅读下面给出的示例,以更好地了解Interactive Ruby如何评估表达式。

    irb(main):001:0> 120*78
    =>9360

    irb(main):002:0> 5-4
    =>1

    irb(main):003:0> 70/10
    =>7

There may be chances when you need the following lifesaving ruby terminal commands to pop out from the problem in which you are stuck:

当您需要以下救生Ruby终端命令来摆脱卡住的问题时,可能会有机会:

  • CTRL+c: It is used for interrupting the current process. If you are stuck in an endless or infinite loop then use this command in the terminal.

    CTRL + c :用于中断当前进程。 如果您陷入无限循环或无限循环中,请在终端中使用此命令。

  • CTRL+d: It is used for ending the IRB session and it takes you back into your terminal shell at the same time.

    CTRL + d :用于结束IRB会话,同时将您带回到终端Shell。

翻译自: https://www.includehelp.com/ruby/ruby-environment-setup-installation-of-ruby-on-mac-and-windows-operating-system.aspx

mac ruby 环境变量

你可能感兴趣的:(python,linux,java,ubuntu,git)