# Set up a Ruby development environment

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/en-us/help/ruby/llms.txt).

## Process overview

This topic explains the process of setting up a Ruby development environment on your local machine. Note that there is no one process that is equally good for all platforms and purposes. We only recommend some of the best practices, which you will pick from based on your own needs and local machine operating system.

## Install Ruby

In this topic, we focus on the reference implementation of Ruby (Ruby MRI), although RubyMine also [supports](supported-ruby-versions.html) alternative implementations, such as JRuby or TruffleRuby.

There are plenty of options, which are described in the [Installing Ruby](https://www.ruby-lang.org/en/documentation/installation/) topic. The key factors to consider are:

* Your operating system (Linux, macOS, Windows)

* Preferred tools: system package managers (Homebrew, atp, etc.), Ruby version managers (rbenv, RVM), and Ruby installers (ruby-build, ruby-install), RubyInstaller > **Note:** > In many cases, combinations of more than one are used in the installation process.

* (For Windows) Whether you are planning to use Rails

If you have difficulty choosing your solution, we suggest that you use one of the few procedures below. They utilize the methods we consider most popular and straightforward among users today.

Expand the procedure for your platform to read the details.

### Install Ruby on Linux

This procedure explains how to install Ruby on your Linux system using the rbenv tool considered one of the most popular Ruby version managers. It allows installing different versions of Ruby and easily switching between them.

Procedure:

1. (Prerequisites) Do the following before installing Ruby:

* Update your Linux distribution by running the following commands in your terminal: ```SHELL sudo apt update sudo apt upgrade ``` You will be asked for your login and password. After you enter both, press `Enter`. Then, when prompted, press `Enter` one more time.

* Install the required packages and libraries by running the command below: ```SHELL sudo apt install gcc make libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev libyaml-dev ``` When prompted, press `Enter`. You may be required to re-enter your login and password (press `Enter` then).

2. Install rbenv:

1. Clone the rbenv repository:

```SHELL
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
```

2. Set up rbenv on your system:

```SHELL
~/.rbenv/bin/rbenv init
```

When completed, close the terminal window and open a new one to make sure the changes take effect.

3. Install the ruby-build plug-in by running the following command:

```SHELL
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
```

4. Install Ruby:

1. (Optional) To view the latest stable version of Ruby, run the following command in the terminal:

```SHELL
rbenv install -l
```

2. To install a specific version of Ruby, run this command:

```SHELL
rbenv install {your_ruby_version}
```

3. Verify your installation by running the command below:

```SHELL
ruby -v
```

You should get the Ruby version you selected to install.

Related links

* [More about rbenv](https://github.com/rbenv/rbenv)

* [More about the ruby-build plug-in](https://github.com/rbenv/ruby-build#readme)

Alternative method

Other popular methods of installing Ruby on Linux are by using Ruby Version Manager (RVM) or Ubuntu's APT package manager. Find more details [here](https://www.ubuntumint.com/install-ruby-ubuntu/).

### Install Ruby on macOS

Ruby is included by default in macOS since El Capitan (10.11). However, this is an outdated version not designed for customer use. We recommend installing Ruby through version managers to ensure the compatibility of all dependencies required for your projects and avoid any permission issues.

Procedure:

This procedure explains how to install Ruby on your macOS system using the rbenv tool considered one of the most popular Ruby version managers. It allows installing different versions of Ruby and easily switching between them.

1. (Prerequisites) You will need the Xcode IDE and the Homebrew package manager. Unless they're already on your system, do the following:

1. Run the following command in your terminal:

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

This will install Homebrew, which should automatically download and install Xcode.

2. Run the `brew config` command to check the installation of Homebrew. Specifically verify the line for Xcode.

3. If Xcode is still not installed, run the `xcode-select --install` command.

> **Note:**
> Generally, Homebrew provides enough details and instructions to follow in case there is a missing component or compatibility issue. Read them carefully and follow the suggested tips.

Now you're system is ready for Ruby installation.

2. Install rbenv:

1. Run the following command:

```SHELL
brew install rbenv
```

2. After the installation is complete, run the following command:

```SHELL
rbenv init
```

3. Close your terminal tab and open a new one to make sure the changes take effect.

4. Verify that the installation was successful by running the command below:

```SHELL
rbenv -v
```

You should get the rbenv version installed on your system.

3. Install Ruby:

1. To view the latest stable version of Ruby, run the following command in the terminal:

```SHELL
rbenv install -l
```

2. To install a specific version of Ruby, run this:

```SHELL
rbenv install {your_ruby_version}
```

4. Verify your Ruby installation:

```SHELL
ruby -v
```

You should get the Ruby version you selected to install.

Related links

* [More about rbenv](https://github.com/rbenv/rbenv)

* [More about Homebrew](https://brew.sh/)

Alternative method

Another popular method of installing Ruby on macOS is by using Ruby Version Manager (RVM). Find more details [here](https://rvm.io/).

### Install Ruby on Windows

There are two popular methods of installing Ruby on Windows:

* RubyInstaller: self-contained Windows-based installer

* Windows Subsystem for Linux (WSL): recommended if you plan to work with Ruby on Rails

Procedure:

There are two popular methods of installing Ruby on Windows:

* RubyInstaller: self-contained Windows-based installer

* Windows Subsystem for Linux (WSL): recommended if you plan to work with Ruby on Rails

Select the tab for your preferred method and follow the instruction.

RubyInstaller:

Procedure: Use the RubyInstaller tool

1. Go to [this page](https://rubyinstaller.org/downloads/) and download the desired version of the Ruby installer.

> **Note:**
> Make sure to select an option with Devkit to install the MSYS2 system, which is required to install Ruby gems.

2. Run the downloaded executable file. This will open the Ruby installer wizard.

3. On the first page of the wizard, check the I accept the License checkbox and click the Next button.

4. On the next page of the wizard, do the following:

1. Specify where to install Ruby: leave the default option or specify a new location.

2. Click the Next button.

5. On the next page of the wizard, make sure the MSYS2 development toolchain checkbox is selected and click the Next button. This will launch the process of extracting files.

6. Once all files are extracted, you will see the final page of the wizard. Leave the Run ‘ridk install’ to set up MSYS2 and development toolchain checkbox selected and click the Finish button.

7. A terminal window will pop up with MSYS2 installation settings. Leave everything at default and press `Enter`. This will install the selected components, followed by a window with a success message. Press `Enter` again.

8. Verify your Ruby installation by running the following terminal command:

```SHELL
ruby -v
```

This should return the Ruby version installed to your system.

WSL:

Procedure: Configure WSL

1. Download and install a WSL distribution (for instance, Ubuntu) from [Microsoft Store](https://jb.gg/clion-wsl) on your Windows machine.

For this step, be sure to use at least Windows 10 or later with the latest “Fall Creators Update” (minimum version 1709, build 16299.15). See the official guide [Install the Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) for instructions.

To work with WSL 2, your Windows version should be 10 build 18917 or later. Follow [these instructions](https://docs.microsoft.com/windows/wsl/wsl2-install#set-a-distro-to-be-backed-by-wsl-2-using-the-command-line) to switch the distributive.

2. Run the Linux distribution.

Upon the first launch, the system may prompt you to enable the Windows optional feature. In this case, you need to do the following:

* Open Windows PowerShell as Administrator and run ```SHELL Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux ```

* Restart your computer.

> **Note:**
> If you are using Linux distribution other than Ubuntu, ensure that the distribution has the [iproute2](https://wiki.linuxfoundation.org/networking/iproute2) package installed or install it manually once the WSL instance is deployed.

3. (Optional) If your Linux distribution doesn't come with `rsync`, you need to install it, for example:

Debian, Ubuntu:

```CONSOLE
apt-get install rsync
```

Fedora:

```CONSOLE
yum install rsync
```

Now that you can use Linux commands, follow the [procedure above](#install-ruby-on-linux) to install Ruby.

> **Tip:**
> Apart from the local Ruby environment, RubyMine allows you to use Ruby installed in WSL or in a Dev Container through [native interpreters](configuring-language-interpreter.html#native_ruby_interpreters), and Ruby installed in Docker or on a remote machine through [remote
> interpreters](configuring-language-interpreter.html#add_remote_ruby_interpreter).

After you install a Ruby interpreter on your system, make sure to [configure it](configuring-language-interpreter.html) in RubyMine.

## Set up Ruby gems

The [installed Ruby interpreter](#ruby) is supplied with a set of third-party libraries. Most of these libraries are distributed as gems, packaged libraries or applications that can be installed with a tool called RubyGems. This tool is bundled with Ruby MRI, so most likely, you don't need to install it separately. You can learn more about this tool from the [official Ruby documentation](https://www.ruby-lang.org/en/libraries/).

> **Tip:**
> RubyMine provides the ability to display the RubyGems environment for a current project from the main menu by using the `Tools | Show Gem Environment` command. The invoked dialog shows the RubyGems and Ruby versions, the installation directory, and so forth.

## Set up Bundler

To manage dependencies specifically required for each of your projects, you will use a tool called [Bundler](https://bundler.io/). This tool lists each project's dependencies in [Gemfiles](https://bundler.io/gemfile.html), which are placed in respective project root directories.

Normally, the [installed Ruby interpreter](#ruby) comes with Bundler installed, but its version can differ from the one required for your project. In such cases, RubyMine suggests installing the required version. Learn how RubyMine integrates with Bundler from the [Bundler](using-the-bundler.html) topic.

> **Tip:**
> If you have any issues related to installing Bundler, check out the [Troubleshooting common issues](https://bundler.io/doc/troubleshooting.html) guide.

## Set up a Rails development environment

To work with Rails projects in the IDE, you need to install the rails gem and its dependencies to the [Ruby interpreter](#ruby).

> **Note:**
> If you plan to use Rails on Windows, make sure to [install Ruby using WSL](#wsl).

Procedure: Install Rails gem

There are several options to do it in RubyMine:

1. When creating a new Rails application, you can install the 'rails' gem right from the [New Project wizard](creating-and-running-your-first-language-project.html#create_rails_app).

2. For existing projects, add the 'rails' gem to your `Gemfile` and install it [using Bundler](using-the-bundler.html).

3. Open the embedded RubyMine [terminal emulator](terminal-emulator.html) and execute the `gem install rails` command.

The next step in this process is installing dependencies required for Rails projects.

Procedure: Install Git

When you [create a new Rails project](creating-and-running-your-first-language-project.html#create_rails_app), make sure to install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) beforehand. This step is necessary since RubyMine automatically creates a local Git repository for all new Rails projects.

> **Note:**
> If you don't want RubyMine to create a Git repository, specify the `--skip-git` [Rails option](creating-and-running-your-first-language-project.html#create_rails_app) in the New Project dialog.

Procedure: Install database tools

Rails development heavily relies on using relational databases. The most common database management systems (DBMS) used in Rails are SQLite, MySQL, and Postgres. To work with a desired DBMS , we recommend that you install the respective package using your system package manager. For example, to install Postgres, use one of the commands below:

* macOS ```SHELL brew install postgresql ```

* Linux (including WSL for Windows) ```SHELL sudo apt install postgresql postgresql-contrib ```

> **Tip:**
> We suggest referring to respective documentation for further instructions.

> **Note: Database support in RubyMine**
> RubyMine provides a [database management functionality](relational-databases.html) that allows you to query, create, and manage databases.

Procedure: Install JavaScript tools

Rails applications can contain JavaScript modules managed in the following ways:

* [Webpacker](https://github.com/rails/webpacker): a wrapper gem on Webpack – the popular tool used for managing and bundling JavaScript code.

* [Asset Pipeline](https://guides.rubyonrails.org/asset_pipeline.html): a legacy framework for working with JavaScript and CSS assets in Rails.

Note that the Webpacker is a default JavaScript compiler starting with Rails 6. To use Webpacker in your applications, you need to install the following tools:

* [Node.js](https://nodejs.org/en/download/): a JavaScript runtime.

* [Yarn](https://yarnpkg.com/lang/en/docs/install/): a dependency manager for JavaScript libraries.

After that, you can install JavaScript dependencies right from RubyMine and work with your [JavaScript code](javascript-specific-guidelines.html).

