Offset: 0.0s
Space Play/Pause

I replaced Docker with THIS.

Are you a developer who loves the idea of reproducible environments but gets bogged down by the friction of tools like NPM, RVM, or even Docker for local development? If you’re seek…

6 min read

Devbox: The Ultimate Tool for Reproducible Development Environments

Are you a developer who loves the idea of reproducible environments but gets bogged down by the friction of tools like NPM, RVM, or even Docker for local development? If you’re seeking a more streamlined, “Zen” approach to managing your local setups, you’re in the right place. After years of searching for the perfect solution, we’ve found a tool that truly ticks all the boxes: Devbox. This powerful command-line tool promises to bring simplicity and reliability to your workflow, making environment management a breeze.

[00:17.842]

Devbox is a command-line tool that lets you easily create isolated shells and containers. You start by defining the list of packages required by your development environment, and Devbox uses that definition to create an isolated environment just for your application.

[00:19.642]

At its core, Devbox provides a CLI that lets you create reproducible and reliable development environments. It allows you to define a specific set of packages for your project, building an isolated shell where those tools are available without polluting your main system. This means no more “it works on my machine” issues. The environment is portable and can be shared with your team, ensuring everyone is on the same page.

[00:22.019]

The magic of Devbox is its simplicity. Imagine you need to work on a Go project, but you don’t have Go installed globally. Outside the Devbox environment, running go version would fail. However, once you initialize Devbox in your project and add the go package, you can enter a dedicated shell where the go command is available, completely isolated from your global setup.

[00:25.261]

What truly elevates Devbox is its extensive plugin system. It comes with a multitude of pre-built plugins for various services and languages. This makes managing different types of environments incredibly straightforward. Whether you need a specific version of a database, a web server, or a programming language, there’s likely a plugin to handle the heavy lifting for you.

Under the Hood: The Power of Nix

[00:43.911]

It’s important to clarify that Devbox, created by the team at Jetify, is not a replacement for Nix. Instead, it’s a user-friendly layer built on top of it. Devbox is powered by Nix and its massive package manager, which is the largest of its kind. While Nix itself is incredibly powerful, it has a steep learning curve and can be complex to manage directly.

Devbox abstracts away the complexities of the Nix language, providing an approachable interface to harness its power for creating development environments. It gives you the benefits of Nix’s reproducible builds without needing to become a Nix expert.

[00:52.887]

Devbox is an open-source project written in Go with a thriving community, as evidenced by its over 10,000 stars on GitHub. This strong community backing ensures continuous improvement and support. The creators, Jetify, also developed Nixhub, a dedicated search engine for Nix packages, further demonstrating their deep expertise and commitment to the Nix ecosystem.

Getting Started with Devbox

[01:38.651]

Getting Devbox up and running is as simple as a single command. The documentation is clear and easy to follow, but the tool itself is so intuitive that you can get started in just a few minutes.

[01:41.071]

Everything starts with a curl command to install the Devbox binary.

curl -fsSL https://get.jetify.com/devbox | bash

The script will download and install the latest version. Since it installs system-level Nix components, it will require sudo permission. Once installed, you’re ready to create your first project-specific environment.

[01:59.621]

The real power of Devbox lies in its project-specific configurations. To start, navigate to your project’s directory and run devbox init. This command creates a devbox.json file, which will serve as the configuration hub for your environment.

[02:10.518]

The devbox.json file is where you define everything your project needs. It includes a packages array to list your dependencies, a shell section for initialization hooks (init_hook), and a scripts section to define custom commands, similar to npm run.

Creating an Isolated Shell

[02:22.758]

With your configuration in place, running devbox shell drops you into a new, isolated shell. This shell has access to all the packages defined in your devbox.json.

[04:33.718]

[A split-screen terminal view comparing the version of ripgrep inside the Devbox shell (13.0.0) versus the global version outside the shell (14.1.1).]

A simple demonstration highlights this isolation perfectly. You can have one version of a tool like ripgrep installed globally (e.g., version 14.1.1) but specify an older version in your devbox.json (e.g., ripgrep@13.0.0). Inside the devbox shell, running rg --version will show version 13.0.0, while outside, it remains 14.1.1. This is achieved without containers or complex virtual machines, just the power of Nix paths.

Seamless Workflow with Direnv Integration

Manually entering and exiting a shell can become tedious. This is where the integration with Direnv shines. Direnv is a utility that automatically loads and unloads environment variables based on your current directory.

[06:00.320]

By running devbox generate direnv, Devbox creates a .envrc file. Now, whenever you cd into your project directory, Direnv automatically activates the Devbox shell and all its packages. When you cd out, the environment is unloaded. This creates a completely seamless and automatic workflow.

Beyond Projects: Global Packages and Services

[06:42.238]

Devbox isn’t just for project-specific “devboxes.” It can also manage global tool installations. If you want a tool like ranger to be available everywhere but managed via Devbox, you can use the devbox global add command. This provides a clean way to manage system-wide tools without cluttering your global environment directly.

[08:47.882]

One of the standout features of Devbox is its powerful plugin system, which simplifies managing services like databases or web servers.

[09:12.986]

For example, by adding nginx to your project, the Nginx plugin is automatically activated. This not only installs Nginx but also creates all necessary configuration files from a template inside a .devbox.d directory within your project. You can then start, stop, and manage Nginx as a background service using devbox services commands. All configuration is self-contained and version-controlled with your project.

[10:03.117]

For a more interactive view, devbox services up launches Process Compose, a terminal-based UI reminiscent of Docker Compose and K9s. It provides a real-time dashboard to monitor your running services, view logs, and manage their state, offering a robust solution for complex multi-service applications.

With Devbox, the dream of hassle-free, reproducible, and portable development environments is finally a reality. It masterfully combines the raw power of Nix with an elegant, user-friendly interface, making it an indispensable tool for any developer looking to streamline their workflow.