Devbox Extension
Devbox has an accompanying VSCode extension that makes the experience of integrating your devbox environment in VSCode much simpler.
Syncing VSCode with Devbox shell
Follow the steps below to have VSCode’s environment be in sync with Devbox shell:- Install Devbox’s VSCode extension
- Open a project that has a devbox.json file in VSCode
- Open command palette in VSCode (cmd+shift+p) and type:
Devbox: Reopen in Devbox shell environment
- Press Enter and wait for VSCode to reload.
- The newly opened VSCode is now integrated with the environment defined your devbox.json. You can test it by checking if packages defined in devbox.json are available in VSCode integrated terminal.
Automatic Devbox shell in VSCode Terminal
Devbox extension runsdevbox shell
automatically every time VSCode’s integrated terminal is
opened, if the workspace opened in VSCode has a devbox.json file.
This setting can be turned off in VSCode’s settings. Simply search for devbox.autoShellOnTerminal
in settings or add the following to VSCode’s settings.json:
devbox shell
is not necessary if VSCode is reopened in Devbox shell environment
via the steps described in Syncing VSCode with Devbox shell
Direnv Extension
Direnv is an open source environment management tool that allows setting unique environment variables per directory in your file system. For more details on how to set it and integrate it with Devbox visit our Direnv setup guide. Once Direnv is installed and setup with Devbox, its VSCode extension can also be used to integrate the environment defined in your devbox.json to VSCode. To do that follow the steps below:
- Install Direnv (link to guide)
- Setup Devbox shell with Direnv (link to guide)
- Install Direnv’s VSCode extension
- Open your Devbox project in VSCode. Direnv extension should show a prompt notification to reload your environment.
- Click on reload.
Windows Setup
Devbox CLI is not supported on Windows, but you can still use it with VSCode by using Windows Subsystem for Linux (WSL). If you’ve set up WSL, follow these steps to integrate your Devbox shell environment with VSCode:
- Install Devbox in WSL.
- Navigate to your project directory. (
C:\Users
is/mnt/c/Users/
in WSL). - Run
devbox init
if you don’t have a devbox.json file. - Run
devbox shell
- Run
code .
to open VSCode in Windows and connect it remotely to your Devbox shell in WSL.
Manual Setup
VS Code is a popular editor that supports many different programming languages. This section covers how to configure VS Code to work with a devbox Java environment as an example.
Setting up Run and Debugger
To create a devbox shell make sure to have devbox installed. If you don’t have devbox installed follow the installation guide first. Then follow the steps below:-
devbox init
if you don’t have a devbox.json in the root directory of your project. -
devbox add jdk
to make sure jdk gets installed in your devbox shell. -
devbox shell -- 'which java
to activate devbox shell temporarily and find the path to your executable java binary inside the devbox shell. Copy and save that path. It should look something like this:
- Open VS Code and create a new Java project if you don’t have already. If VS Code prompts for installing Java support choose yes.
- Click on Run and Debug icon from the left sidebar.
- Click on create a launch.json link in the opened sidebar. If you don’t see such a link, click on the small gear icon on the top of the open sidebar.
-
Once the
launch.json
file is opened, update theconfigurations
parameter to look like snippet below:
-
Use
java
command to run the compiled project. For example, to run the sample project from above: