1
0
Fork 0
mirror of https://codeberg.org/Mo8it/How_To_Linux.git synced 2024-11-25 00:31:35 +00:00

Add packages.md

This commit is contained in:
Mo 2022-08-22 03:26:13 +02:00
parent 6abbb589ac
commit 3ffe5d5df2
2 changed files with 75 additions and 0 deletions

View file

@ -5,6 +5,7 @@
- [Day 1](day_1/README.md) - [Day 1](day_1/README.md)
- [Why learn Linux?](day_1/why_linux.md) - [Why learn Linux?](day_1/why_linux.md)
- [Terminal basics](day_1/terminal_basics.md) - [Terminal basics](day_1/terminal_basics.md)
- [Packages](day_1/packages.md)
- [Day 2](day_2/README.md) - [Day 2](day_2/README.md)
- [Day 3](day_3/README.md) - [Day 3](day_3/README.md)
- [Day 4](day_4/README.md) - [Day 4](day_4/README.md)

74
src/day_1/packages.md Normal file
View file

@ -0,0 +1,74 @@
# 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" 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 ads or your browser search machine is overwritten. 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 the repository. The package manager does also take care of verifying the downloaded package 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 the book uses a Fedora system for demonstrations, the package manager that 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 adminstrative priviliges. 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 then need some time to sync some data, but 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` now. Congratulations, you are now a hacker! 💻🤓
To exit the matrix, press `q`.
If you don't like the matrix and you 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`.
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
[![](https://imgs.xkcd.com/comics/sandwich.png)](https://xkcd.com/149/)
Lets try to install another package, this time without `sudo` at the beginning of the command.
```console
$ 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 priviliges for running this command.
Any action that might modify the system needs adminstrative priviliges. 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 distructive 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 alway 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 adminstrators 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:
[![](https://imgs.xkcd.com/comics/incident.png)](https://xkcd.com/838/)
> 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!