What is the command to install Ruby?

Improve Article

Save Article

Prerequisite: Ruby Programming Language
 
Before we start with the installation of Ruby on Windows, we must have first-hand knowledge of what Ruby is?. Ruby is a pure Object-Oriented language developed by Yukihiro Matsumoto (also known as Matz in the Ruby community) in the mid-1990s in Japan. Everything in Ruby is an object except the blocks but there are replacements too for it i.e procs and lambda. The objective of Ruby’s development was to make it act as a sensible buffer between human programmers and the underlying computing machinery.
 
Ruby is based on many other languages like Perl, Lisp, Smalltalk, Eiffel and Ada. It is an interpreted scripting language which means most of its implementations execute instructions directly and freely, without previously compiling a program into machine-language instructions.

Downloading and Installing Ruby

All the versions of Ruby for Windows can be downloaded from rubyinstaller.org. Download the latest version and follow the further instructions for its Installation.

What is the command to install Ruby?

Beginning with the installation:

Installing MYSYS2 Components:
 

To check if Ruby installed correctly, perform a version check for the same using the following command on the command-line:

ruby -v

What is the command to install Ruby?

Here’s a sample Program to begin with the use of Ruby Programming:
Let’s consider a simple Hello World Program.

 
Using command-line, run the irb command. After this we can write the ruby code and it will run on command line.

What is the command to install Ruby?

If you're using Ruby on a Mac, it is set up by default, but you can't modify or upgrade it. Most developers don't use the pre-installed version of Ruby on their Macs. Instead, they configure several systems to help them manage Ruby installation (and other programs), and manage different versions of Ruby. In this lesson, we'll cover installing the version of Ruby and version management tools that are used on Epicodus computers.

Take note: if you run into any error that prevents you from completing all of the installation steps in this lesson, you should still continue with the remaining installation pre-work by installing Postgres.

Also make sure to take detailed notes on any issues that come up, the troubleshooting steps you took to address those issues, and any helpful resources you found along the way. You can share these notes with your peers, and they can share their notes with you.


We'll install Ruby using chruby and ruby-install. If you have installed Ruby before, you may be using RVM (Ruby Version Manager). You may stay with RVM if it is working for you but we recommend using chruby and ruby-install, which we will go over here. To uninstall RVM, type $ rvm implode.

Homebrew Installation

If you do not have Homebrew installed yet, you may install it now by copy and pasting this command into the command line:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This installs Homebrew on your device, a package manager for OS X that makes it easy to install developer software.

Next, ensure Homebrew packages are run before the system versions of the same (which may be dated or not what we want) by executing the following:

For bash users: shell $ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile

For zsh users: shell $ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.zshrc

Install ruby-install

To install ruby-install, a tool for installing Ruby, run this command:

$ brew install ruby-install

Install Ruby

To install the version of Ruby we use at Epicodus, run this command:

$ ruby-install ruby 3.1.2

If you get the following error configure: error: clang version 3.0 or later is required, you'll need to install Xcode developer tools first:

$ xcode-select –-install

Optionally, you can run $ rm -rf ~/src/ to remove the source code that ruby-install downloaded as you won't need it anymore. As always, be very careful using the $ rm -rf command. Alternatively, once you are using VS Code, you can use $ code ~/src/ to open the directory in VS Code, look at the Ruby source code there, and remove it manually.

Install and Configure chruby

To install chruby, a program to manage which versions of Ruby you're using, run this command:

$ brew install chruby

Next, configure your shell's environment variables for chruby by running the following two commands. This will set up bash or zsh to use chruby and also set up auto-switching of Ruby versions.

For bash users:

$ echo 'source /usr/local/opt/chruby/share/chruby/chruby.sh' >> ~/.bash_profile
$ echo 'source /usr/local/opt/chruby/share/chruby/auto.sh' >> ~/.bash_profile

For zsh users:

$ echo 'source /usr/local/opt/chruby/share/chruby/chruby.sh' >> ~/.zshrc
$ echo 'source /usr/local/opt/chruby/share/chruby/auto.sh' >> ~/.zshrc

To set your default Ruby version to 3.1.2, run this command:

$ echo "ruby-3.1.2" > ~/.ruby-version

The last configuration I'd recommend is to not install documentation when you install Ruby gems. Why? It takes longer than installing the gems themselves, and better documentation is available online. Optionally, run this command:

$ echo "gem: --no-rdoc --no-ri" > ~/.gemrc

Verify Your Ruby Installation

In your Terminal, run this command to verify the version of Ruby you've installed:

$ ruby -v

Also, confirm that you can access IRB (a REPL, which we'll learn more about soon):

$ irb
irb(main):001:0>

To exit IRB, enter exit.

Install Rails

Finally, verify that you can install Rails at the same version we use at Epicodus:

$ gem install rails -v 7.0

You can verify that Rails is working by navigating to the desktop and creating a new project:

$ rails new test_project

It will take a little time for Rails to spin up a new project. Once it's complete, cd into test_project and start the Rails server:

$ rails s

You should see a message similar to the following:

Puma starting in single mode...
* Puma version: 5.6.4 (ruby 3.1.2-p20) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 19756
* Listening on http://[::1]:3000
* Listening on http://127.0.0.1:3000

If not, remember to copy and paste the entire error log into a document that you can share with your instructor. To close the server enter ctrl + c.

After you've completed these steps, delete the test_project directory.

And with that, you're ready to go!

Next steps

Check out the READMEs for chruby and ruby-install, or at least bookmark them for later, so you know how to install other versions of Ruby and switch between them as needed. There's also an upcoming lesson on Managing Ruby Versions that goes into detail about using the tools ruby-install and chruby.

Otherwise, continue working through the Ruby and Rails pre-work!

Lesson 3 of 7
Last updated more than 3 months ago.

Is Ruby installed on Linux?

Depending on your distribution, Ruby may or may not be pre-installed on your Linux system. If not, you can install it with your package manager, e.g., RPM, Yum, DPKG, etc. Regardless, the ruby program will end up in the /usr/bin and /usr/lib/ruby directories, just like on a Mac.

What is the command to install rails?

Step 1: Type the following command in the ruby terminal: $ gem install rails. ... .
Step 2: To verify that rails have been installed, type the following command and it should report its version. ... .
Step 3: To make your first web application in rails type the following command in the command line: $ rails new project..

What is Ruby Installer?

This is a self-contained Windows-based installer that includes the Ruby language, an execution environment, important documentation, and more. Download. Add-ons.

Can you install Ruby on Windows?

Downloading and Installing Ruby All the versions of Ruby for Windows can be downloaded from rubyinstaller.org. Download the latest version and follow the further instructions for its Installation.