1
0
Fork 0
mirror of https://codeberg.org/Mo8it/How_To_Linux.git synced 2025-04-25 00:44:18 +00:00
How_To_Linux/src/day_1/packages.md
2022-08-22 09:25:34 +02:00

6.3 KiB

Packages

So far, we did only use commands that are common in every Linux system.

Now, we want to start exploring additional commands that might not be preinstalled on your system.

Therefore, we need to learn how to install so called packages to get access to additional programs.

Package managers

In Linux, you don't install programs by using a search engine to find a website, then visit the website and download an installer, then run the installer and click "Next" and "Agree" 100 times without even reading what you are agreeing to.

This method is too insecure. You have to trust the website that you did visit. You have to hope that no malware is delivered while you are downloading the installer from the website. You can get the malware either from the website itself or through a man-in-the-middle attack. Then the installer might do whatever it wants. You just click "Next" and suddenly your system shows you (extra) ads or your browser search preferences are overwritten with Yahoo. Surprise! 🎉

In Linux, you (mainly) install software through the package manager that ships with your distribution. The software is then downloaded from a repository which is a collection of packages that is managed by the distribution. The distribution managers make sure that no malware is added to their repositories.

The package manager does take care of verifying the downloaded packages before installation. This is done using some cryptographic methods and prevents man-in-the-middle attacks or installation of packages that were corrupted during the download process.

The package manager does also take care of installing any other packages that you did not specify but are required by the package that you want to install. These packages are called dependencies.

Since this book uses a Fedora system for demonstrations, the book will use Fedora's package manager dnf.

If you are using another Linux distribution, you might need to replace the commands of dnf with apt for Debian based distributions for example.

It is important to understand the functionality of package managers. Then you can transfer this knowledge to other package managers if required. This applies to some other aspects in Linux too, since the Linux operating system does not exist. There are distributions that bundle a set of software and differ in small ways.

To install a package, you need administrative privileges. Therefore, we need some sudo powers. sudo will be explained in the next section.

Lets install our first package! To do so, enter sudo dnf install cmatrix. You will be asked for the password of your user. Type the password and then press Enter. For security reasons, you will not be able to see you password while entering it. So don't wonder why nothing happens while typing the password. Just type it and then press Enter.

The package manager might need some time to sync some data, then it will show you a summary of what it will do and ask you for confirmation. Type y for yes and then press Enter for the installation to start.

After the installation is done, you can enter cmatrix. Congratulations, you are a hacker now! 💻🤓

To exit the matrix, press q.

What if you don't like the matrix and want to remove it? You can uninstall packages using sudo dnf uninstall PACKAGENAME. In this case: sudo dnf uninstall cmatrix. You have to confirm again with y.

Why do we speak about packages instead of programs when installing software on Linux? Because packages can contain more than one binary (the actuall programs) and extra files. Take a look at the files that are installed with cmatrix on Fedora for example.

Warning ⚠️ : While installing or uninstalling packages, it is important to take a look at the summary before confirming the action with y. There is a reason why a confirmation is required. Sometimes, some packages depend on packages with older versions than the versions that exist on your machine. If you want to install those packages anyway, other packages that depend on the newer versions can break!

Just don't blindly press y. If the package manager gives you a warning before doing something, enter this warning in a search engine and read about what it means before continuing.

Sudo

Lets try to install another package, this time without sudo at the beginning of the command.

$ dnf install cowsay
Error: This command has to be run with superuser privileges (under the root user on most systems).

You can see that you get an error resulted by a lack of privileges for running this command.

Any action that might modify the system needs administrative privileges. Installing a package (system-wide) is one of these actions.

Sometimes, an action might not modify the system, but a user might be restricted through the permissions system to not be able to access a file for example. In this case, you would also need to use sudo.

Linux has a superuser, one user that exists on every Linux system and is able to do anything! This user is the root user. For security reasons (and also to not do something destructive by a mistake), this user is often locked. sudo allows you as a non root user to run your command as a root user.

You are not always allowed to use sudo. If you don't own the machine you are using and just share it with others, then there is a high chance that only administrators of the machine have sudo access.

If you don't have access to sudo and try to use it, then you get an output like this:

Warning ⚠ : Use sudo with great caution! Do not run a command from the internet that you don't understand! Especially if it needs to be run with sudo! RED FLAG! 🔴

Look up a command before you run it.

Even commands that you know like rm can destroy your system if you use them with sudo without knowing what they are doing.

You might find a "meme" in the internet that tells you to run something like sudo rm -rf /. This command will delete EVERYTHING on your machine. It is like delete the C and all other drives at the same time on Windows.

Linux assumes that you know what you are doing when you use sudo. With great power comes great responsibility!