sodcalculator

10 Tech How-To

Install Vault on Ubuntu: Step-by-Step Guide

Guide 10-61068 · Updated · Step by step

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

  1. 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.
  2. Install required tools
    Install curl and unzip if they aren’t already present:
    sudo apt install -y curl unzip
  3. Download the Vault binary
    Go to the Vault downloads page to find the latest version number. Then replace 1.15.0 in 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), use linux_arm64 instead of linux_amd64.
  4. 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.zip
    sudo mv vault /usr/local/bin/
  5. Verify the installation
    Check that Vault is installed correctly:
    vault --version
    You should see output like Vault v1.15.0.
  6. 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
  7. 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.d
    sudo 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

  8. Create the data directory
    Create the directory where Vault will store its data and set proper ownership:
    sudo mkdir -p /opt/vault/data
    sudo chown -R vault:vault /opt/vault/data
  9. 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

  10. Start and enable the service
    Reload systemd, enable the service to start at boot, and start it:
    sudo systemctl daemon-reload
    sudo systemctl enable vault
    sudo systemctl start vault
  11. Check the service status
    Verify that Vault is running:
    sudo systemctl status vault
    You should see active (running) in the output.
  12. 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 using vault server -dev instead. 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.
  13. 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 shows Sealed: false.
  14. 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:8200 by default, which will fail if you’re using HTTP. Always set export 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=debug to 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.gpg
    echo "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.list
    sudo apt update && sudo apt install vault
    This method simplifies future upgrades.
  • Enable bash autocompletion – Run vault -autocomplete-install and 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 ~/.bashrc or ~/.zshrc to 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/data to 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 with sudo chown -R vault:vault /opt/vault/data), or a syntax error in the config file (validate with vault 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 has address = "127.0.0.1:8200".
  • “command not found: vault” – The binary isn’t in your PATH. Confirm it’s in /usr/local/bin and 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

The whole Tech How-To bed →