Various sorts of packages, including text editors, internet browsers, and picture viewers, are required to run the system according to your demands. You must install extra packages because not all of them are installed by default. Package managers and the source code can both be used to install them. Debian (.deb) and Red Hat (.rpm) is the most used package formats in Linux. The ‘.deb’ files are used in Debian, Ubuntu, and Linuxmint type distributions, and the ‘.rpm’ files are used in red hat enterprise Linux, fedora, and centos type distributions.
Chrome, Photoshop, VLC, and other software packages contain a large number of files that are merged into a single package. Upstream providers are the folks who create the program in its entirety. They deliver their packages to package maintainers and put up instructions for users when they release new software. These package maintainers examine, handle, and distribute this software as packages. The software packages are downloaded, installed, and upgraded via package managers.
One thing to note here is that most of the packages need other shared libraries to run properly. These libraries are known as dependencies of the package. So, to use a package on your system, you must ensure that all the dependencies are installed before.
Repositories of Package
Unlike Windows, you do not need to go to the software’s download website to install it. All hosts have their own repositories. It’s a centralized storage facility where Linux gets and installs applications. Compiled packages for various Linux distributions and versions are available in these repositories. You can install any kind of software from these repositories using the package managers.
Tar and gzip
Tarball (tar.gz) is a method of compressing and combining many files into a single file. In Linux, it’s a relatively popular file format for Linux file system. You’ve probably seen the.rar or.zip file formats before. These are file archives, which means they contain several files inside.
Compressing files with gzip
It is used for compressing files and creating a new file with the extension of .gz. Let’s see how we can compress a file using gzip.
$ gzip hello.txt
Here, we compressed the hello.txt file though it is not necessary as the text file has a lower file size. This is done for illustration purposes. Next, you can see a hello.txt.gz file in the same directory. To uncompress the ‘.gz’ file you need to use ‘gunzip’.
$ gunzip hello.txt.gz
Creating archives with tar
As I have mentioned before the usefulness of archive files comes from combining multiple files into one with compression. Unfortunately, with gzip, you can not add multiple files. Do not worry! For this purpose, Linux offers you a tar command. It creates files with a .tar extension.
$ tar cvf tarfile.tar file1 file2 file3
In this example, three ‘.txt’ files are combined into a tar file. You may ask about the options that passed in the command. Let me break it to you.
- c: for creating
- v: verbose
- f: filename
You have to set a filename that you want as a tar file. Running the ‘ls’ command, you can see there is a tarfile.tar file in the same directory. To extract a tar file run the following command.
$ tar xvf tarfile.tar
Here, ‘x’ indicates that the file should be extracted, whereas ‘v’ and ‘f’ indicate the same as previously. Another file format you’ll come across regularly is.tar.gz, which is an archived and compressed file. You may make this type of file by first archiving files with the tar command, then compressing with the gzip tool.
$ gzip tarfile.zip
You can also do the same thing easily by tar command. Follow the command below.
$ tar czf myfile.tar.gz file1 file2
Here, the ‘z’ option tells us to create a ‘.tar.gz’ file. In this way, you can archive and compress in one command line. You can also extract the file in the same way.
$ tar xzf myfile.tar.gz
rpm and dpkg
To install a package, Linux uses “.deb” and “.rpm” files, similar to how Windows uses.exe files. You won’t see these files if you install a package from the package repository. However, you may install a program by downloading a “.deb” or “.rpm” file. You may use the package management commands rpm and dpkg to install these direct packages. The dependencies are not installed automatically by these programs. Before installing the package you intend to utilize, you must manually install the dependencies.
Install a package
To install a package using rpm or dpkg, you need to run the following command.
$ dpkg -i deb_file.deb
$ rpm -i rpm_file.rpm
Here, ‘i’ stands for install. You can also remove any packages using the dpkg or rpm command.
$ dpkg -r deb_file.deb
$ rpm -e rpm_file.rpm
In Debian ‘r’ stands for remove, and in RPM ‘e’ refers to erase. You can also check the packages that are installed in your system.
$ dpkg -l
$ rpm -qa
In Debian ‘l’ denotes a list and in RPM ‘q’ and ‘a’ stand for query and all respectively.
Yum and apt
In Linux, the most popular package management systems are yum and apt. Yum is used in Red Hat Enterprise and APT is used in the Debian distributions. To install a package from a package repository you need to run the following command.
Debian: $ apt install package_name
RPM: $ yum install package_name
To remove a package from the system, you need to run the command below.
Debian: $ apt remove package_name
RPM: $ yum erase package_name
You can also update packages.
Debian: apt update; apt upgrade
RPM: yum update
Compile source code
Most of the basic packages can be installed using package management tools. But you will face more often that some packages can not be installed this way. You need to get it from the source code. In this section, I will show you how you can get it done.
To begin, you’ll need the tools necessary to compile the source code. Run the Linux command below.
$ sudo apt install build-essential
Well, now you need to extract the contents of your installation file which mostly comes in .tar.gz form. To extract the files run the following command:
$ tar -xzvf package.tar.gz
Look for the README or INSTALL file in the contents directory, which provides the essential instructions. You’ll also find a configure script that checks your system for dependencies.
This will install the dependencies if anything is found missing. The “./” command runs a script in the current directory. Now, there will be another file named Makefile that contains the instructions for building the package. For this, you need to run the make command.
Finally, you can install the package by running the command below.
$ sudo make install
To uninstall the package from your system, you need to run the following command.
$ sudo make uninstall
It’s important to remember that the make uninstall command may not remove all of the package’s additions. To accomplish this in a more efficient manner, create a “.deb” file from the contents directory first.
$ sudo checkinstall
This command generates a “.deb” file that you can use to install the package together with all of its dependencies and to remove the package in a more straightforward manner.