Vagrant: Working with Reproducible Development Environments
JetBrains Rider integrates with Vagrant helping you create reproducible development environments defined by Vagrantfile configuration files. You can create and delete virtual boxes, initialize Vagrant boxes, configure remote interpreters by reading settings from the Vagrant configuration files, and execute other Vagrant commands without leaving the IDE. You can also choose among several virtual boxes when performing the vagrant up command (Multiple Vagrant configuration).
In the context of JetBrains Rider, the following terms are used to denote Vagrant-specific notions:
A Vagrant box in the JetBrains Rider user interface or Vagrant base box in the current documentation is a box in the native Vagrant terminology. It denotes a pure image, a skeleton, on the base of which a specific environment is customized, provisioned, and deployed on your machine.
An instance is a virtual machine. In other words, it is a specific environment customized, provisioned, and deployed on your machine on the base of a Vagrant base box and in accordance with a Vagrantfile. In other similar products and documentation, an instance can be referred to as virtual machine.
An instance folder is the folder where the relevant Vagrantfile is stored after initialization and where JetBrains Rider will look for it. By default, it is the project root folder.
Preparing to work with Vagrant
Before you start, ensure that the following steps and checks are done:
Make sure that you have Vagrant and Oracle's VirtualBox installed on your computer and the parent folders of their executable files are added to the system
PATHvariable. If you followed the standard installation procedure, these folders are added automatically.
- Make sure that the parent folders of the following executable files are added to the system PATH variable:
vagrant.bat or vagrant from your Vagrant installation. This should be done automatically by the Vagrant installer.
VBoxManage.exe or VBoxManage from your Oracle's VirtualBox installation.
Click Vagrant under Tools. The Vagrant page page opens.
Specify the Vagrant executable file. Because the parent folder of the executable file has been already added to the system PATH variable, type just the name of the executable.
In the Instance Folder field, specify the fully qualified path to the directory where the Vagrantfile is initialized and stored. A Vagrantfile is a configuration file that defines the instance ( virtual machine) you need. The file contains the virtual IP address, port mappings, and the memory size to assign. The file can specify which folders are shared and which third-party software should be installed. According to the Vagrantfile your instance (virtual machine) is configured, provisioned against the relevant Vagrant base box, and deployed on your computer. A Vagrantfile is created through the
When creation of an instance (virtual machine) is invoked either through the
vagrant upcommand or through the menu option, JetBrains Rider looks for the Vagrantfile in the directory specified in the Instance folder field. For more information, see http://docs.vagrantup.com/v2/vagrantfile/.
You can create a Vagrantfile in any directory and appoint it as instance folder. If the field is empty, JetBrains Rider will treat the project root as the instance folder and look for a Vagrantfile in it.
In the Vagrant Boxes area, configure a list of the predefined Vagrant base boxes available in JetBrains Rider. Each item presents a Vagrant base box on which Vagrant configures and launches its instances (virtual machines). The entries of this list correspond to the output of the command
vagrant box list.
To download a new base box, click the Add button . In the dialog that opens, specify the URL address to access the base box and the name to refer to it in JetBrains Rider. By default, JetBrains Rider suggests the URL to the lucid32 box.
This command corresponds to
vagrant box add <name> <URL>. As a result, the specified base box is downloaded to your machine.
To remove a base box, select it in the list and click the Remove button . The base box and the nested files are physically deleted from the disk. This command corresponds to
vagrant box remove <name>.
Initializing the Vagrantfile
A Vagrantfile is a configuration file that defines the instance ( virtual machine) you need. The file contains the virtual IP address, port mappings, and the memory size to assign. The file can specify which folders are shared and which third-party software should be installed. According to the Vagrantfile your instance (virtual machine) is configured, provisioned against the relevant Vagrant base box, and deployed on your computer. A Vagrantfile is created through the
vagrant init command.
You can initialize the Vagrantfile in any folder, just keep in mind that this folder should be specified as the instance folder on the Vagrant page of the Settings Preferences dialog. Otherwise JetBrains Rider will be unable to find the relevant Vagrantfile during the instance (virtual machine) creation.
To initialize the Vagrantfile, do one of the following:
Initialize the Vagrantfile
To have the Vagrantfile created in the project root, choose on the main menu and select the target project root from the list that opens. The output of the
initcommand is displayed in the Run tool window.
cd <directory to initialize the Vagrantfile in> vagrant init <base box name> <base box url>
After the Vagrantfile is created, you can preview it in the Editor: it contains the detailed list of the available configuration options. Alter or add configuration settings, if needed. Note that code completion is enabled for Vagrantfile.
Once the Vagrantfile initialization is successfully completed, you are ready to import the base box, provision and deploy it according to the Vagrantfile, thus creating your own instance (virtual machine).
Creating and launching an instance (virtual machine)
Creating an instance (virtual machine) means importing and provisioning a base box according to the Vagrantfile located in the instance folder.
Create an instance, follow these steps:
Do one of the following:
Select the desired virtual machine configuration from the suggestion list:
Stopping, suspending, resuming, reloading, and destroying an instance (virtual machine)
Reload an instance
If you have made some changes to the Vagrantfile and want a running virtual machine updated in accordance to them, choose on the main menu or run the following command in the embedded Terminal:For details, see http://docs.vagrantup.com/v2/cli/reload.html.
Suspend an instance
To temporary stop the operating system on a running virtual machine (guest machine) and save the exact state of the environment as it is at this moment so it can be resumed exactly from this point, choose on the main menu or run the following command in the embedded Terminal:For details, see http://docs.vagrantup.com/v2/cli/suspend.html.
Resume an instance
To resume a previously suspended operating system on a virtual machine (guest machine) and have it run from the state saved at the suspension moment, choose on the main menu or run the following command in the embedded Terminal:For details, see http://docs.vagrantup.com/v2/cli/resume.html.
Shut an instance down
To shut down the operating system on a virtual machine (guest machine), choose on the main menu or run the following command in the embedded Terminal:For details, see http://docs.vagrantup.com/v2/cli/halt.html.
To shut down the operating system on a virtual machine (guest machine), stop the virtual machine itself, and remove the resources provisioned on it during the creation
vagrant up, choose on the main menu or run the following command in the embedded Terminal:For details, see http://docs.vagrantup.com/v2/cli/destroy.html.