Linux+: Applications 18 – Install, Upgrade and Remove Packages with apt-get

J

Jarret W. Buse

Guest
Linux+: Applications 18 – Install, Upgrade and Remove Packages with apt-get

With any computer system, Linux being no exception, a user needs to install, upgrade and remove applications. In Linux, the applications are kept in a 'package' which contains all necessary information to manage the application.

The basic syntax for apt-get is:

apt-get [subcommand] [package_name]

NOTE: Some subcommands may have a varying syntax, but the above is the general syntax for all subcommands.

The subcommands for installing, upgrading and removing packages are as follows:

  • installing
  • upgrade
  • dist-upgrade
  • remove
  • purge
  • autoremove
  • source
  • build-dep
  • download

NOTE: Be aware that apt-get will manage necessary dependencies for the package. This feature is what makes apt-get an enhancement to the dpkg tool.

The “install” subcommand is used to install packages, which seem obvious. The “package_name” used is the package name and not the full package name (file name) which includes the “.deb” extension.

The syntax for the “install” subcommand allows for multiple package names to be listed separated only be a space. For instance, if you wanted to install the Cinnamon desktop as well as Samba, you could use the following command:

apt-get install samba cinnamon

NOTE: You will need root privileges to perform most apt-get commands. If you are not logged in as root, you will need to use “sudo” before each “apt-get” command.

It is assumed that package names are intended to be installed. Even with the install command, packages can be removed as well. To specify a package to be installed, use a plus “+” before the package. To remove a package, use a minus “-” sign before the package name. In this way, multiple packages can be installed and/or removed. For instance, assume you wanted to install Samba and remove Cinnamon; the syntax would be:

apt-get install +samba -cinnamon

If a package name is given that is already installed, the package will be upgraded if a newer version exists.

To perform an upgrade on each installed package, this could be a tedious job. On a system with multiple packages installed you may want to upgrade them all. To perform a system-wide package upgrade, if one exists, use the “upgrade” subcommand. The upgrade command is as follows:

apt-get upgrade

The “upgrade” subcommand may not deal well with dependency files. The subcommand “dist-upgrade” will cause dependencies to be upgraded, and if needed, to remove dependencies no longer required. The command is as follows:

apt-get dist-upgrade

Removing unneeded packages is another simple task. The subcommand is “remove” and requires the list of packages to remove. The subcommand is nearly identical to the “install” subcommand. Multiple package names can be listed. A “+” can be used to install a package and a “-” to remove a package. The remove subcommand will remove the package and dependencies if they are not needed by other packages. The only thing not removed are configuration files. If the package is reinstalled, the configuration files are still present. To remove “samba” and “cinnamon”, use the following command:

apt-get remove samba cinnamon

If I wanted to install samba and remove cinnamon, I could use the following command:

apt-get remove +samba -cinnamon

If you wanted to remove a package and also make sure the configuration files were removed, then use the “purge” subcommand. Multiple packages can be purged by listing the package names separated by a space. For example, to purge both samba and cinnamon, use the command:

apt-get purge samba cinnamon

When a package is installed, required dependencies are installed by apt-get automatically. If any of these dependencies are no longer needed, they can be removed with the “autoremove” subcommand. The command is:

apt-get autoremove

When packages are downloaded to the system, they are not kept in the typical download folder of “/var/cache/apt/archives/”. Downloaded source packages are placed in the current directory where the command is executed. Packages can be downloaded as source files which need to be compiled. To download source files, use the “source” subcommand:

apt-get source calligra

Here, the source files for “calligra” are downloaded into the current folder.

To get dependencies for the source file the subcommand is “build-dep”. Here, dependencies can be satisfied for a given source package. The subcommand causes dependencies to be downloaded and used to install a package. To get all dependencies for a package name, the command is:

apt-get build-dep calligra

The last subcommmand is “download”. Similar to the “source” subcommand, the “download” subcommand will get the specified package. The package retrieved contains the binary files which are stored in the current folder. Remember that the downloaded files are not installed. To download the binary files for Samba, the command would be:

apt-get download samba

These subcommands should provide a good starting point to using apt-get. Be sure to practice and understand them. These can be more important for normal use and not just the certification exam.
 

Attachments

  • slide.jpg
    slide.jpg
    32.9 KB · Views: 10,723

Members online


Latest posts

Top