Installing Prebuilt Binaries in Ubuntu
The primary way of installing software in Ubuntu and other Debian-based distros is through apt-get. It downloads packages from repositories and installs them locally. However, sometimes you might have to install packages that come as prebuilt binaries.
How does apt-get work?
apt-get
locates packages on the software repositories listed in /etc/apt/sources.list or /etc/apt/sources.list.d.
It uses dpkg as backend to perform the installation on your system.
In order to locate where a package has been installed, run dpkg -L package_name
.
1 | dpkg -L vim |
The example above displays all the files that come with the vim package. Run apt show vim
to get more details.
Prebuilt packages
Things can be really smooth with apt
or apt-get
, but when dealing with prebuilt packages, some manual intervention is required.
These packages generally come as .tar.gz
archives containing compiled binaries for a specific platform. You have to extract them and
move the contents to /usr/local or /opt for a system-wide installation. /usr/local
is for use by the system administrator when installing software locally, while /opt
if for installing packages that are not part of the operating system. It’s up to you which one you choose, in my experience either
works fine. Let’s say you want to install a prebuilt package named example.tar.gz. Note that any of the steps described bellow may require root privileges.
- Make sure the package is not already installed in /usr/local or /opt. If that’s the case, remove all files from the previous
installation:
rm -rf /opt/example
. - Extract the contents of the archive into the desired location.
1
tar -C /opt -xzf example.tar.gz
- -C is used to change the target directory
- x is used to extract files from the archive
- z is used to filter the archive through gzip. For .tar.xz archives use J instead of z, and for .tar.bz2 use j.
- f indicates the archive to be processed
- Add the newly installed binaries to the
PATH
environment variable. The executables are typically stored in the /bin folder of the package, so in this case we are looking for /opt/example/bin. To modify thePATH
variable only for the current user, edit your ~/.bashrc file (assuming you’re using bash) or your~/.profile
and add the bin folder toPATH
. To make the binaries available system-wide, edit /etc/profile. You may need to restart your shell for the changes to take effect.1
export PATH="$PATH:/opt/example/bin"
Real examples
Go
You can find the official tutorial on golang.org.
- Download the archive. Make sure to choose a recent version.
1
wget https://golang.org/dl/go1.17.2.linux-amd64.tar.gz
- Remove files from the previous installation, if any.
1
sudo rm -rf /opt/go
- Extract the archive.
1
sudo tar -C /opt -xzf go1.17.2.linux-amd64.tar.gz
- Edit the
PATH
variable into your ~/.bashrc and then reload bash config by runningsource ~/.bashrc
, or simply restart the shell.1
2# This line should be in your .bashrc file.
export PATH="$PATH:/opt/go/bin" - Check it out.
1
2go version
go version go1.17.2 linux/amd64
ArangoDB
Note that this may also be installed using apt-get
. You can find details on arangodb.com.
- Choose your version and download the server archive.
1
wget https://download.arangodb.com/arangodb38/Community/Linux/arangodb3-linux-3.8.1.tar.gz
- Remove files from the previous installation, if any.
1
sudo rm -rf /opt/arangodb3-linux-3.8.1
- Extract the archive.
1
sudo tar -C /opt -xzf arangodb3-linux-3.8.1.tar.gz
- Edit the
PATH
variable into your ~/.bashrc and thensource ~/.bashrc
or restart the shell.1
2# This line should be in your .bashrc file.
export PATH="$PATH:/opt/arangodb3-linux-3.8.1/bin" - Check it out.
1
2
3
4
5
6arangod --version
3.8.1
architecture: 64bit
# ...
# long output cropped
Clang + LLVM
Make sure the release is compatible with your OS version. Official releases available on github.
- Download the archive.
1
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
- Remove files from the previous installation, if any.
1
sudo rm -rf /opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04
- Extract the archive. Be mindful of the file extension.
1
sudo tar -C /opt -xJf clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
- Edit the
PATH
variable into your ~/.bashrc and thensource ~/.bashrc
, or restart the shell.1
2# This line should be in your .bashrc file.
export PATH="$PATH:/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin" - Check it out.
1
2
3
4
5clang --version
clang version 10.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin