Install your own command-line tools
Install your own command-line tools in a workspace and make them persist across rebuilds.
On this page
Now that you launched your first workspace, you can add your favorite command-line tools to every workspace.
The Quickstart template installs system languages through the Programming Languages parameter, but it doesn't carry the small command-line tools you may often use, such as bat or ripgrep.
You can install those yourself with a package manager like Homebrew or mise.
In this guide, you install both Homebrew and mise, install a tool with each, and learn which installs survive a workspace restart and why. You then change the template so the Homebrew tools persist too, and finish by making your tools install in every new workspace automatically.
Note
This guide works inside a running workspace from the Quickstart template. Most of it runs in the workspace, but the last two steps edit the template so Homebrew persists and every new workspace ships with your tools.
What you'll do
- Check mark Install command-line tools with Homebrew and mise into your workspace.
- Check mark Restart the workspace and see which tools persist.
- Check mark Learn why one persists and the other doesn't.
- Check mark Wire up Homebrew so its tools persist too.
- Check mark Preinstall your tools in every new workspace from the template.
What persists in a workspace
A Quickstart workspace keeps your home directory, /home/coder, on a persistent volume.
Everything outside /home/coder comes from the workspace image, and Coder rebuilds it from that image every time the workspace starts.
A tool survives a restart only when both of these are true:
- The tool installs into
/home/coder. - Your shell finds the tool through a file in
/home/coder, such as.bashrc.
You'll install tools two ways and restart to see this rule decide which ones stay, change the template so Homebrew follows the rule too, then preinstall your tools in every new workspace.
Install Homebrew and mise
Open a terminal in your workspace.
Install Homebrew with its setup script:
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Homebrew installs to /home/linuxbrew/.linuxbrew.
Add it to your shell so the brew command is available:
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"Confirm Homebrew is available before you continue:
brew --versionInstall mise with its setup script:
curl -fsSL https://mise.run | shmise installs to ~/.local/bin/mise, inside your home directory.
Activate it so every new shell loads it:
echo 'eval "$(~/.local/bin/mise activate bash)"' >> ~/.bashrcActivation only takes effect in shells that start after this change, so open a new terminal (or run source ~/.bashrc) before you use mise.
Until you do, mise doctor reports that mise isn't activated, which is expected at this point.
For other shells, refer to Activate mise.
Open a new terminal so both the Homebrew and mise changes take effect, then confirm each manager runs:
brew --version
mise --versionNote
If you manage ~/.bashrc with dotfiles, add the brew shellenv and mise activate lines to the .bashrc in your dotfiles repository instead, so applying your dotfiles doesn't overwrite them.
Install a tool with each manager
Install ripgrep with Homebrew:
brew install ripgrepInstall bat with mise:
mise use -g batConfirm both tools run:
rg --version
bat --versionBoth work. So far, the two package managers look interchangeable.
Restart the workspace and compare
Restart the workspace. The restart rebuilds the container from the image and keeps only your home directory.
Open your workspace in the Coder dashboard and select Restart. When it's back, reconnect by reopening the web terminal.
When you reconnect, your shell prints an error before you run anything:
bash: /home/linuxbrew/.linuxbrew/bin/brew: No such file or directoryThat's the first sign something changed.
Your .bashrc still tries to load Homebrew, but the restart removed it.
Check each tool to see what survived.
bat, installed with mise, still works:
bat --versionbat 0.26.1rg, installed with Homebrew, is gone:
rg --versionbash: rg: command not foundSo is brew itself:
brew --versionbash: brew: command not foundmise installed bat under /home/coder, which persists, so bat survived.
Homebrew installed ripgrep to /home/linuxbrew, outside /home/coder, so the rebuild discarded Homebrew and every formula you installed with it.
The brew shellenv line stayed in your .bashrc because it lives in /home/coder, which is why your shell still tries to load the missing brew and prints the error above.
Make Homebrew survive restarts
To make Homebrew survive a restart, you'll edit the template and add a persistent volume.
The volume backs /home/linuxbrew, the prefix where Homebrew installs, so Homebrew and its formulae stay between restarts.
Note
This step assumes your Quickstart template is open for editing. If it's not, you can edit the template from the web by finding the template, selecting the three dots menu, and selecting Edit files. Refer to Customize workspace startup for more information.
In main.tf, add a volume for Homebrew's directory next to the existing home_volume:
resource "docker_volume" "homebrew_volume" {
name = "coder-${data.coder_workspace.me.id}-homebrew"
lifecycle {
ignore_changes = all
}
}Then mount it in the docker_container "workspace" resource, alongside the block that mounts /home/coder:
volumes {
container_path = "/home/linuxbrew"
volume_name = docker_volume.homebrew_volume.name
read_only = false
}Publish the change and restart the workspace:
In the web editor, make the edits above in main.tf.
Select Build, wait for the build to pass, then select Publish.
On your workspace's home tab, select Update and restart.
The restart gives you a persistent but empty /home/linuxbrew.
Your earlier Homebrew install is gone, so install it once more.
This time it lands on the volume:
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"The brew shellenv line is still in your .bashrc from Step 1, so open a new terminal to load it, then reinstall ripgrep:
brew install ripgrepRestart the workspace once more and reconnect. This time the startup error is gone, and both tools report their versions:
rg --version
brew --versionHomebrew now persists because /home/linuxbrew lives on its own volume, the same way mise's tools persist because they live in /home/coder.
Install your tools in every new workspace
Steps 1 through 4 set up your tools in this workspace. To give everyone who uses the template the same tools, install them from the template so every new workspace starts with them.
The template already installs languages on every start with the install_languages script.
You'll add a second script that installs your command-line tools the same way.
Note
This step edits the template. If it isn't open for editing, refer to Customize workspace startup.
mise is the lighter choice here.
It installs prebuilt binaries into /home/coder, which already persists, so the first start stays quick and later starts reuse the tools.
In main.tf, add a script next to the existing install_languages resource:
resource "coder_script" "install_tools" {
agent_id = coder_agent.main.id
display_name = "Install Tools"
icon = "/icon/terminal.svg"
run_on_start = true
script = <<-EOT
#!/usr/bin/env bash
set -e
# Install mise on first start. It lives in /home/coder, so later starts reuse it.
if [ ! -x "$HOME/.local/bin/mise" ]; then
curl -fsSL https://mise.run | sh
fi
export PATH="$HOME/.local/bin:$HOME/.local/share/mise/shims:$PATH"
# Install the tools for everyone who uses the template, tracking the latest release.
mise use -g ripgrep@latest bat@latest
# Load mise in new interactive shells so the tools are on PATH.
if ! grep -qs 'mise activate' "$HOME/.bashrc"; then
echo 'eval "$(mise activate bash)"' >> "$HOME/.bashrc"
fi
EOT
}mise use -g ripgrep@latest bat@latest writes the tools to mise's global config at ~/.config/mise/config.toml and installs them, so every workspace from the template resolves the same versions.
Publish the change and apply it to your workspace:
In the web editor, add the install_tools resource to main.tf.
Select Build, wait for the build to pass, then select Publish.
On your workspace's home tab, select Update and restart.
When the workspace is back, confirm both tools run without installing anything by hand:
rg --version
bat --versionThe script runs on every start, so every new workspace from the template now ships with ripgrep and bat.
What just happened
The two package managers behaved differently for one reason: where each one installs.
- mise installs into
~/.local/share/mise, inside your home directory, and activates from~/.bashrc. Both are in/home/coder, so its tools persist with no template change. - Homebrew installs to
/home/linuxbrew, outside/home/coder, so its tools are discarded on every restart until you mount that path on a persistent volume.
To keep a tool, choose the approach that matches who needs it:
- For a tool that's yours alone, install it with mise. It persists through restarts with no template change.
- To keep your Homebrew tools, mount
/home/linuxbrewon a persistent volume, as you did in Step 4. This is a template change, so it affects everyone who uses the template. - To preinstall a tool in every new workspace, add it to the template's startup script, as you did in Step 5 with mise.
You can also install system packages with
apt-get, as in Add a programming language, or bake the tool into the workspace image.
The rule underneath all of these: a tool persists when it lives in a part of the workspace that persists. Refer to Resource persistence for how Coder decides what survives a restart.
Final code
What's next?
Now that you can install your own tools, clone private repositories so your workspaces can reach your private GitHub code.
Learn more
- Homebrew documentation for the package manager
- mise documentation for the version manager
- Resource persistence in the Coder documentation
- Dotfiles in the Coder documentation