Bundler
IntelliJ IDEA supports integration with Bundler and enables you to handle gem dependencies for your application right inside the IDE.
Install Bundler
As a rule, the installed Ruby interpreter comes with Bundler installed. If not, you can install Bundler to the project SDK in one of the following ways:
Select
from the main menu.Press Ctrl twice and execute the
gem install bundler
command in the invoked popup.Open the IntelliJ IDEA terminal emulator and execute the
gem install bundler
command.
Bundle init
After installing Bundler, you can generate a Gemfile for the current project:
Select
from the main menu.
Install gems
You can install gems defined in the Gemfile to the project interpreter as follows:
Do one of the following:
Press Ctrl twice. In the invoked popup, start typing bundler, select
bundle install
and press Enter.Select
from the main menu.Open the Gemfile, place the caret at any highlighted gem missing in the project SDK and press Alt+Enter. Select Install missing gems using 'bundler' and press Enter.
(Optional) If the current project interpreter does not have the required Bundler version specified in Gemfile.lock, IntelliJ IDEA suggests installing it.
In the Bundle Install dialog, click Install to run the
bundle install
command without any arguments.If necessary, pass the required arguments when running this command, for example:
--without production
: install all gems except ones mentioned in the production group within the Gemfile.--path vendor/bundle
: install gems to the vendor/bundle project directory. In this case, Bundler 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.
Wait until gems are installed. The Run tool window will display this process:
You can see the installed gems in both the Project Settings | Modules | Ruby SDK and Gems Ctrl+Alt+Shift+S page...
... and the External Libraries node of the Project view Alt+1:
Install gems to a 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.
Bundle exec
IntelliJ IDEA provides the capability to run and debug Ruby and Rails applications, run tests, and deploy your code in a universal way - by using run/debug configurations. Run/debug configurations provide the default set of startup parameters that allow you to run the desired command quickly. You can execute any of these commands in the context of the bundle in the following way:
Open the Run/Debug Configuration dialog in one of the following ways:
Select
from the main menu.With the Navigation bar visible ( ), choose from the run/debug configuration selector.
Press Alt+Shift+F10 and then press 0.
In the opened Run/Debug Configurations dialog, select the required configuration and open the Bundler tab.
Configure the Run the script in the context of the bundle ('bundle exec') option:
Auto-detection: select this option to run your code with
bundle exec
when it is possible.Disabled: select this option to disable the use of
bundle exec
.
Click OK.
Run bundle check in dry mode
IntelliJ IDEA provides an option to run bundle check
in dry mode. In this case, Bundler will not create or update your lockfile.
From the main menu, go to
Ctrl+Shift+A.Start typing
Run silent bundle check with --dry-run
. Select the option and press Enter to enable it.Once you've enabled this option, you will need to maintain your lockfile yourself. After changing your Gemfile, run
bundle check
/bundle lock
to update your lockfile.