Using the Bundler
IntelliJ IDEA supports integration with Bundler and enables you to handle gem dependencies for your application right inside the IDE. To use this capability, you need to install the Bundler gem to the project SDK.
Install Bundler
To install the Bundler gem to the project SDK, select . You can also install the Bundler gem along with other gems from the Gemfile.
Create Gemfile
If your project does not contain the Gemfile, you can create it by choosing the command. This command is available when the Gemfile doesn’t exist.Install Gems to Local Interpreter
You can install gems defined in the Gemfile to the project interpreter in one of the following ways:
Click Update, Clean, etc.
. Within this menu, you can also use other Bundler commands such as-
Install missing gems using the Missing gem inspection provided by the IDE. For example, open the Gemfile, place a caret to any highlighted gem missing in the project SDK and press Alt+Enter:
-
When you open a project or change the project SDK, the following message displays:
Click Install to install missing gems. If Bundler is not installed the following message appears:
Click Yes.
In the Bundle Install dialog, click Install to run the bundle install
command without any arguments:
You can also pass the required arguments when running this command:
The Run tool window will display a process of installing gems:
You can see the installed gems in both the Project Settings | Modules | Ruby SDK and Gems (Ctrl+Shift+Alt+S) page...
… and the External Libraries node of the project tree:
Install Gems to Project
IntelliJ IDEA allows you to work with gems installed not only to the SDK but to a project itself. To do this, pass the following argument when running the bundle install
command: --path vendor/bundle
In this case, Bundler installs gems into the vendor/bundle directory and adds the .bundle/config file to a project’s root. IntelliJ IDEA processes this configuration file to detect that gems are installed into vendor/bundle.
Local gems will be displayed in the External Libraries node of the project tree:
Install Gems to Remote Interpreter
If you are using a remote Ruby interpreter, IntelliJ IDEA uses the Gemfile placed on a remote machine to install the gems. This requires configuring mappings between files of a local and remote project. To do this, click the Edit Path Mappings button in the Ruby SDK and Gems page:
In the Edit Project Path Mappings dialog, specify the local and remote project root paths:
After you configured mappings, install gems using the Install Gems to Local Interpreter instruction.
Note that when you are using a remote interpreter, IntelliJ IDEA downloads gems from a remote machine to a local cache to be able to use code insight features. In this case, you may encounter a situation when new gems were installed on a remote machine outside the IDE. To update a set of gems stored in a local cache, click the Synchronize gems button in the Ruby SDK and gems page.