Skip to content

Installing software ​

By the end of this lesson you can install, update and remove software with a package manager, explain why the shell finds some programs and not others, run a program you downloaded, and check that a download arrived intact.

You will use sudo from Permissions here, because installing software changes the system. It is one of the jobs sudo is for.

Packages and package managers ​

On Linux you rarely download installers from websites. Instead, software comes as packages: a program, its files, and a list of the other packages it needs (its dependencies). A package manager fetches packages from trusted servers called repositories, installs the dependencies too, and later updates everything at once.

text
 you ── sudo apt install htop ──▶ apt ──▶ repository (Ubuntu's servers)
                                   │      └─ htop + what it depends on
                                   ▼
                     installed, on your PATH, updated with the system

Each family of distributions has its own:

DistributionPackage managerInstall example
Debian, Ubuntu, Mintaptsudo apt install htop
Fedora, RHEL familydnfsudo dnf install htop
Arch Linuxpacmansudo pacman -S htop
openSUSEzyppersudo zypper install htop

apt in practice ​

The everyday apt commands, on Debian and Ubuntu:

CommandWhat it doesNeeds sudo?
sudo apt updateRefreshes the list of available packages. Run it before installingYes
sudo apt upgradeInstalls updates for everything already installedYes
apt search htopSearches package names and descriptionsNo
apt show htopDescribes one package: version, size, dependenciesNo
sudo apt install htopInstalls a package and its dependenciesYes
sudo apt remove htopRemoves itYes
apt list --installedLists everything installedNo
text
sam@laptop:~$ apt show htop
Package: htop
Version: 3.4.1-5build2
…
Installed-Size: 451 kB
Depends: libc6 (>= 2.38), libncursesw6 (>= 6), libtinfo6 (>= 6)
…
Description: interactive processes viewer

apt update does not install anything; it only fetches the latest list. Forgetting it is the usual reason apt install cannot find a package that you know exists.

Snap and Flatpak, in brief ​

Two newer formats work on most distributions:

  • A snap bundles a program with what it needs, updates itself in the background, and runs in a sandbox that limits which files it can touch. Snap comes with Ubuntu. sudo snap install NAME, snap list.
  • A Flatpak is similar and popular for desktop apps. Most come from the Flathub repository. flatpak install flathub APP-ID, flatpak update.

Programming languages have their own package managers too, such as pip for Python and npm for JavaScript. Use those inside a project or a virtual environment, as the LogLens install does with python3 -m venv, never with sudo.

For the channels Dhiva Labs apps use (the Snap Store, the Dhiva Labs PPA, .deb files and tarballs), see Installing Dhiva Labs apps.

PATH: how the shell finds programs ​

When you type htop, the shell does not search the whole disk. It looks through a short list of folders, in order, and runs the first htop it finds. That list is the PATH variable:

text
sam@laptop:~$ echo $PATH
/home/sam/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
sam@laptop:~$ command -v python3
/usr/bin/python3

The folders are separated by :. command -v NAME (or which NAME) tells you which file a command name runs. If no folder in the list has it, you get:

text
sam@laptop:~$ mytool
mytool: command not found

That message means "not in any PATH folder". The program may be installed somewhere else, or not at all.

FolderWhat goes there
/usr/binPrograms installed by the package manager. Leave it to apt
/usr/local/binPrograms you install by hand for every user, with sudo
~/.local/binPrograms you install for yourself, no sudo needed

On Ubuntu, ~/.local/bin is added to your PATH automatically when you log in, if the folder exists. Elsewhere, add this line to the end of ~/.bashrc and open a new terminal:

bash
export PATH="$HOME/.local/bin:$PATH"

Run a program you downloaded ​

Some tools are a single file you download, such as SysVitals. Three steps, all from earlier lessons:

text
sam@laptop:~/Downloads$ ./mytool
bash: ./mytool: Permission denied
sam@laptop:~/Downloads$ chmod +x mytool
sam@laptop:~/Downloads$ ./mytool
mytool 1.0
  1. Check it with a checksum (next section) before you run it.
  2. Make it executable with chmod +x. Downloads never are, which is a small safety feature.
  3. Run it with a path, ./mytool, because the Downloads folder is not on your PATH. To run it from anywhere, move it into ~/.local/bin.

Programs are built for one kind of processor. uname -m prints yours: x86_64 for ordinary Intel and AMD computers, aarch64 for 64-bit ARM such as a Raspberry Pi. Download files marked amd64/x86_64 or arm64/aarch64 to match. The wrong one fails with cannot execute binary file: Exec format error.

A Windows .exe does not run on Linux at all. WinBridge is a Linux command-line tool that builds Windows programs from your source code and can run them on Linux through a Wine runtime it manages itself; see its beginner guide.

Checksums: did the file arrive intact? ​

A checksum is a long fingerprint calculated from every byte of a file. Change one byte and the checksum changes completely. Many projects publish a SHA-256 checksum next to each download, often in a .sha256 file.

text
sam@laptop:~/Downloads$ sha256sum mytool
e5bf8e13cdaff68a92a84028d91ccfb3e8a9e72953238fad908786de2f3f5c76  mytool
sam@laptop:~/Downloads$ sha256sum -c mytool.sha256
mytool: OK

Compare the first form by eye with the published value (the whole thing, not only the start). The second form, -c, reads the expected value from the .sha256 file and compares for you. If the file was damaged or changed:

text
sam@laptop:~/Downloads$ sha256sum -c mytool.sha256
mytool: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

Delete it and download it again. A checksum proves the file is the one the checksum was made from. It only proves the file is genuine if you got the checksum from the project's official page. Installing Dhiva Labs apps shows the same check on a real release.

Stay safe ​

  • Prefer your distribution's repositories. Packages there are built and checked by the distribution, and update with the rest of the system. Next best is the project's own official channel.
  • Be choosy about extra sources. Every PPA or repository you add can install and update software as root. Add only ones from projects you trust.
  • Read before you run install scripts. curl … | sudo bash runs a stranger's script as root without showing it to you. Download it, read it, then decide.
  • No sudo pip install or sudo npm install -g unless the project tells you to. They can overwrite files your system depends on. Use a virtual environment or your home folder.
  • Check downloads with the published checksum, and remove software you no longer use.
  • Keep the system updated with sudo apt update && sudo apt upgrade (&& runs the second command only if the first succeeds). Most fixes for security problems arrive this way.

Check yourself ​

QuizInstalling software

Question 1 of 6

sudo apt install htop says it cannot find the package, but you know it exists. What do you try first?

Score: 0

What you learned ​

  • A package manager installs packages and their dependencies from repositories, and updates them together.
  • On Debian and Ubuntu: sudo apt update, then sudo apt install NAME. Snap and Flatpak are self-contained, sandboxed alternatives.
  • PATH is the list of folders the shell searches for commands. command not found means the name is in none of them.
  • A downloaded program needs chmod +x and a path such as ./tool, and must match your processor.
  • sha256sum -c checks a download against its published checksum.

Next steps ​