This guide walks you through installing HashiCorp Vault on Ubuntu, covering both the official binary method and the apt repository method. You’ll end up with a working Vault binary, a systemd service for automatic startup, and a basic development server configuration to verify the installation. Before starting, you’ll need a Ubuntu system (20.04 or newer) with sudo access and an internet connection.
What You’ll Need
- Ubuntu 20.04 or later (64-bit)
- A user account with sudo privileges
- Internet access to download Vault
- Basic familiarity with the command line
Step-by-Step
- Update your system packages
Open a terminal and run:sudo apt update && sudo apt upgrade -y
This ensures all existing packages are current, reducing potential dependency conflicts. - Install required tools
Installcurlandunzipif they aren’t already present:sudo apt install -y curl unzip - Download the Vault binary
Go to the Vault downloads page to find the latest version number. Then replace1.15.0in the command below with that version (or use the latest you see):curl -O https://releases.hashicorp.com/vault/1.15.0/vault_1.15.0_linux_amd64.zip
If you’re on an ARM system (like a Raspberry Pi), uselinux_arm64instead oflinux_amd64. - Unzip and move the binary
Unzip the downloaded file and move the binary to a directory in your PATH:unzip vault_1.15.0_linux_amd64.zipsudo mv vault /usr/local/bin/ - Verify the installation
Check that Vault is installed correctly:vault --version
You should see output likeVault v1.15.0. - Create a dedicated system user (optional but recommended)
Running Vault as a non-root user is a security best practice:sudo useradd --system --home /etc/vault.d --shell /bin/false vault - Create a configuration directory and file
Create the directory and a basic config file for a development server (for testing only):sudo mkdir /etc/vault.dsudo tee /etc/vault.d/vault.hcl <<EOF
storage "file" {
path = "/opt/vault/data"
}listener "tcp" {
address = "127.0.0.1:8200"
tls_disable = 1
}ui = true
EOF - Create the data directory
Create the directory where Vault will store its data and set proper ownership:sudo mkdir -p /opt/vault/datasudo chown -R vault:vault /opt/vault/data - Set up a systemd service
Create a systemd unit file so Vault starts automatically on boot:sudo tee /etc/systemd/system/vault.service <<EOF
[Unit]
Description=HashiCorp Vault
After=network-online.target[Service]
User=vault
Group=vault
ExecStart=/usr/local/bin/vault server -config=/etc/vault.d/vault.hcl
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=on-failure
LimitNOFILE=65536[Install]
WantedBy=multi-user.target
EOF - Start and enable the service
Reload systemd, enable the service to start at boot, and start it:sudo systemctl daemon-reloadsudo systemctl enable vaultsudo systemctl start vault - Check the service status
Verify that Vault is running:sudo systemctl status vault
You should seeactive (running)in the output. - Initialize Vault (first-time only)
For a production setup, you need to initialize Vault to generate keys. For a development server, you can skip this by usingvault server -devinstead. For a file-based storage, initialize with:export VAULT_ADDR='http://127.0.0.1:8200'vault operator init
This will output unseal keys and a root token. Save them securely – you cannot recover them if lost. - Unseal Vault
Vault starts sealed. Unseal it using the keys from the previous step. You’ll need at least the threshold number (default 3):vault operator unseal
Enter each key when prompted. Repeat until the seal status showsSealed: false. - Log in with the root token
Use the root token to authenticate:vault login
Paste the root token when prompted.
Common Mistakes
- Forgetting to set VAULT_ADDR – Without this environment variable, the Vault CLI tries to connect to
https://127.0.0.1:8200by default, which will fail if you’re using HTTP. Always setexport VAULT_ADDR='http://127.0.0.1:8200'. - Using the wrong architecture – Downloading the AMD64 binary on an ARM system will result in a “cannot execute binary file” error. Check your architecture with
uname -m. - Running Vault as root – Vault warns against running as root. Use a dedicated user as shown in the steps.
- Misconfiguring the config file – A missing or malformed HCL file can prevent Vault from starting. Use
vault server -config=/etc/vault.d/vault.hcl -log-level=debugto see detailed errors. - Losing unseal keys – If you lose the unseal keys, you cannot unseal Vault and all data becomes inaccessible. Always back them up securely.
Tips
- Use the apt repository for easier updates – HashiCorp provides an official apt repository. To use it, run:
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpgecho "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.listsudo apt update && sudo apt install vault
This method simplifies future upgrades. - Enable bash autocompletion – Run
vault -autocomplete-installand restart your shell to get tab completion for Vault commands. - Set up environment variables – Add
export VAULT_ADDR='http://127.0.0.1:8200'to your~/.bashrcor~/.zshrcto avoid typing it every time. - Use a development server for testing – For quick experiments, run
vault server -dev– it automatically unseals and provides a root token in the output. Never use this in production. - Back up the data directory – Regularly back up
/opt/vault/datato protect against data loss. Also back up the unseal keys and root token separately.
Troubleshooting
- Vault fails to start – Check the logs with
journalctl -u vault -f. Common causes: incorrect permissions on the data directory (fix withsudo chown -R vault:vault /opt/vault/data), or a syntax error in the config file (validate withvault server -config=/etc/vault.d/vault.hcl -dev). - “connection refused” error – This usually means Vault isn’t listening on the expected address. Verify the service is running (
sudo systemctl status vault) and that the config hasaddress = "127.0.0.1:8200". - “command not found: vault” – The binary isn’t in your PATH. Confirm it’s in
/usr/local/binand that your PATH includes that directory (echo $PATH). - Sealed status after restart – This is normal. Vault seals itself on restart. You must unseal it manually or set up auto-unseal (requires cloud KMS or transit engine).
- Permission denied when writing to /opt/vault/data – Ensure the vault user owns the directory:
sudo chown -R vault:vault /opt/vault/data.
Frequently Asked Questions
Can I install Vault using Snap?
Yes, there is a Snap package (sudo snap install vault), but it may not always be the latest version. The official binary or apt method is recommended for production.
Do I need to unseal Vault every time the server restarts?
Yes, unless you configure auto-unseal. For a simple setup, you can manually unseal with the keys. For production, consider using a cloud KMS or a separate Vault cluster as an auto-unseal provider.
What is the default port for Vault?
Vault listens on port 8200 by default. You can change this in the listener configuration.
How do I upgrade Vault?
If you installed via apt, run sudo apt update && sudo apt upgrade vault. If you installed manually, download the new binary and replace the old one, then restart the service.
Is it safe to run Vault as root?
No, HashiCorp explicitly warns against it. Always run Vault as a non-root user, ideally a dedicated system user.
Can I use Vault without a systemd service?
Yes, you can run vault server -config=/etc/vault.d/vault.hcl manually, but using systemd ensures it starts automatically and restarts on failure.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Google Not Working in Chrome? Key Fixes
- Node.js Hosting: Managed Host or Vercel?
- Windows 10/11 Sleep Mode Shortcut: Create & Use
- VPN on Your Smartphone: Should You Install One?
- Open Source Notes App: Pick the Right One
- Google Authenticator for Facebook: Step-by-Step