1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > mac ruby 环境变量_Ruby环境设置| 在Mac和Windows操作系统上安装Ruby

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

时间:2019-01-05 05:09:28

相关推荐

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 aresetting 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 Setup 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-fsSL/Homebrew/install/master/install)

$(curl-fsSLhttps:///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 forsetting 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 /downloads/.

第1步:从/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”以继续检查版本。

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

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

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

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

通过以以下方式编写“ Ruby <program_name> .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> exitorirb(main):001:0> quit

Syntax:

句法:

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

Here is thelist of Command-line optionswhich you may need while working on Interactive Ruby Shell.

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

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=>9360irb(main):002:0> 5-4=>1irb(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。

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

mac ruby 环境变量

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。