Install Go and Rust on Linux
Install Go via the official tarball and Rust via rustup on Linux. Covers PATH setup, multiple versions side by side, and keeping both toolchains updated.
Before you start
- ▸A 64-bit Linux system with internet access
- ▸curl installed (available by default on most distros)
- ▸sudo privileges for extracting Go to /usr/local (not required for rustup)
Go and Rust are both available through their official upstream toolchains—and that is where you should get them. Distro packages lag behind significantly; Go 1.21 shipped in Ubuntu 24.04 while upstream was already at 1.22, and Rust in most repos is months behind stable. This guide uses the canonical install methods: the official Go tarball and rustup for Rust. Both install to your home directory by default, keep your system packages untouched, and let you run multiple versions side by side.
Install Go
1. Download the official tarball
Check go.dev/dl for the latest stable release. At time of writing that is Go 1.22.x. Replace the version string below as needed.
curl -LO https://go.dev/dl/go1.22.4.linux-amd64.tar.gz
Verify the SHA-256 checksum shown on the download page:
sha256sum go1.22.4.linux-amd64.tar.gz
2. Extract to /usr/local
The Go documentation recommends /usr/local/go. Remove any previous installation first to avoid stale files mixing with the new release.
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.22.4.linux-amd64.tar.gz
3. Add Go to your PATH
Add these two lines to ~/.profile (login shells) or ~/.bashrc / ~/.zshrc depending on your shell and preference. GOPATH is where your own modules and binaries land; $GOPATH/bin makes installed tools reachable.
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
Reload without logging out:
source ~/.bashrc
4. Verify the installation
go version
Expected output (version will vary):
go version go1.22.4 linux/amd64
Managing Multiple Go Versions
The Go toolchain supports installing secondary versions as modules. Once your primary go binary is in PATH, install any other version like this:
go install golang.org/dl/go1.21.11@latest
go1.21.11 download
This places a go1.21.11 wrapper in $GOPATH/bin. Call it explicitly when you need the older toolchain. Your default go command is unchanged.
go1.21.11 version
To remove a secondary version, delete its wrapper from $GOPATH/bin and its SDK cache from ~/sdk/go1.21.11.
Install Rust with rustup
1. Install rustup
rustup is the official Rust toolchain manager. It handles the compiler, standard library, cargo, and cross-compilation targets. Do not use distro Rust packages for development work.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
The installer is interactive. For a standard setup, accept the default option 1 (Proceed with installation). It installs to ~/.rustup (toolchains) and ~/.cargo (binaries and registry cache).
Note: If you are uncomfortable piping to sh, download the script first, inspect it, then run it:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init.sh
less rustup-init.sh
bash rustup-init.sh
2. Source the environment
The installer appends a source line to your shell rc file automatically. For the current session:
source "$HOME/.cargo/env"
Future shells will pick this up automatically. If you use a non-standard shell or a minimal dotfile setup, add this line yourself to your rc file.
3. Verify Rust and Cargo
rustc --version
cargo --version
Expected output (version will vary):
rustc 1.78.0 (9b00956e5 2024-04-29)
cargo 1.78.0 (54d8815d0 2024-03-26)
Managing Multiple Rust Toolchains
rustup makes parallel toolchains trivial. The three main channels are stable, beta, and nightly.
Install additional toolchains
rustup toolchain install nightly
rustup toolchain install beta
List installed toolchains
rustup toolchain list
Switch the global default
rustup default stable
Use a specific toolchain for one project
Inside a project directory, create a rust-toolchain.toml file or use the + override syntax:
rustup override set nightly
Or call a toolchain explicitly without changing the project default:
cargo +nightly build
Update all toolchains
rustup update
Required Build Dependencies
Both toolchains need a C linker. Without one, Rust compilation fails immediately and some CGo packages in Go will not build.
Debian / Ubuntu:
sudo apt install build-essential
Fedora / RHEL / Rocky:
sudo dnf groupinstall "Development Tools"
Arch:
sudo pacman -S base-devel
Keeping Things Updated
Updating Go
Go does not have an auto-updater. When a new release appears, repeat the tarball steps: download, verify the checksum, remove /usr/local/go, and extract the new archive. Your GOPATH projects are unaffected.
Updating Rust
One command updates all installed toolchains and rustup itself:
rustup update
Troubleshooting
go: command not found after installation
Your shell has not loaded the updated PATH. Run source ~/.bashrc or open a new terminal. Confirm with echo $PATH that /usr/local/go/bin is present. If you added the export to ~/.profile only, note that many desktop sessions do not source it—prefer ~/.bashrc or ~/.zshrc.
rustc: command not found after rustup install
The installer adds source "$HOME/.cargo/env" to ~/.bashrc and ~/.profile. Open a new terminal or run source "$HOME/.cargo/env" manually. If you use fish, rustup does not write fish syntax automatically—add fish_add_path ~/.cargo/bin to your config.fish.
Rust linker error: linker 'cc' not found
Install build-essential (Debian/Ubuntu), gcc (Fedora), or base-devel (Arch) as shown in the build dependencies section above.
Permission denied writing to /usr/local
The Go tarball extraction requires sudo because /usr/local is root-owned. If you prefer a user-space installation, extract to $HOME/go-sdk/go1.22.4 instead and adjust the PATH export accordingly. rustup never needs sudo; everything goes under $HOME.
Frequently asked questions
- Why not just use the Go or Rust packages from my distro's repository?
- Distro packages frequently lag 3–6 months behind upstream stable releases. Both Go and Rust move quickly; new language features, performance improvements, and security fixes appear regularly. Using upstream installers also avoids dependency conflicts with any system-level package.
- Does rustup require sudo or root access?
- No. rustup installs entirely under $HOME/.rustup and $HOME/.cargo. Never run the rustup installer with sudo unless you explicitly want a system-wide install, which is a non-standard setup rustup does not officially support.
- How do I set a different Rust toolchain for a specific project without affecting others?
- Run rustup override set <toolchain> inside the project directory, or add a rust-toolchain.toml file to the project root with a [toolchain] channel entry. Both methods are local to that directory tree.
- Can I install Go somewhere other than /usr/local if I don't have sudo?
- Yes. Extract the tarball to any directory you own, such as $HOME/go-sdk/go1.22.4, then set PATH to include $HOME/go-sdk/go1.22.4/bin. Everything works identically; only the PATH export changes.
- How do I completely uninstall Rust installed via rustup?
- Run rustup self uninstall. This removes ~/.rustup, ~/.cargo/bin, and the shell rc modifications rustup made. Any projects you built are unaffected.
Related guides
Configure Prometheus Alertmanager
Configure Prometheus Alertmanager with routing trees, receivers, inhibition rules, grouping, Go templates, and PagerDuty/Slack on-call integrations.
Build an Intranet Server on Linux
Set up a complete small-office intranet on one Linux box: Nginx web server, dnsmasq local DNS, Samba file sharing, and a Wiki.js team wiki.
Build an nftables Firewall Script
Build a complete nftables firewall from scratch: tables, chains, sets, default-deny input policy, service allowlisting, and persistent systemd configuration.
Caddy as a Reverse Proxy
Set up Caddy as a reverse proxy with automatic HTTPS, load balancing, WebSocket passthrough, reusable snippets, and header control — no certbot required.