Home > System Tutorial > LINUX > body text

Learn Linux with me: apt command quick reference guide

WBOY
Release: 2024-02-11 15:15:03
forward
448 people have browsed it

apt is a command line utility that enables easy installation, updating, removal and management of deb packages on Ubuntu, Debian and related Linux distributions. Different from the apt-get and apt-cache tools, apt brings together the commonly used commands in the two and adds some improved default options.

The original design intention of apt is to better meet the interactive needs of users. If you need to use apt when writing shell scripts, try to choose apt-get and apt-cache, as they are more reliable in terms of backward compatibility and provide more options and features.

It should be noted that most apt commands need to be run as a user with sudo privileges. Doing this ensures that you have sufficient permissions to perform the required actions.

This guide serves as a quick reference for the apt command.

Update package index (apt update)

The APT Package Index is basically a database that contains records of packages available in the repositories enabled in the system.

To update the package index, run the following command. This will get the latest changes from the APT repository:

[linuxmi@linux:~/www.linuxmi.com]$ sudo apt update

Learn Linux with me: apt command quick reference guide

Always update the package index before upgrading or installing new packages.

Upgrade software package (apt upgrade)

Regularly updating your Linux system is one of the most important aspects of overall system security.

To upgrade installed packages to the latest version, run:

[linuxmi@linux:~/www.linuxmi.com]$ sudo apt upgrade

Learn Linux with me: apt command quick reference guide

This command will not upgrade software packages that require deletion of installed packages.

If you want to upgrade a single package, pass the package name:

sudo apt upgrade package_name

It is a good idea to configure automatic security updates.

Comprehensive upgrade (easy to fully upgrade)

The difference between an upgrade and a full upgrade is that the latter will remove installed packages if the entire system needs to be upgraded.

sudo apt full-upgrade

Be careful when using this command.

Install software package (apt installation)

Installing the package is as simple as running the following command:

sudo apt install package_name

If you want to install multiple packages with one command, specify them as a space-separated list:

sudo apt install package1 package2

To install a local deb file, provide the full path to the file. Otherwise, the command will attempt to retrieve and install the package from the APT repository.

sudo apt install /full/path/file.deb

Delete package (delete)

To remove an installed package, enter the following:

sudo apt remove package_name

You can also specify multiple packages, separated by spaces:

sudo apt remove package1 package2

The remove command will uninstall the given package, but may leave some configuration files behind. If you want to remove a package that contains all configuration files, use purge instead of remove:

sudo apt purge package_name

Remove unused packages (apt autoremove)

Whenever a new package is installed on the system that depends on other packages, the package dependencies are also installed. After removing the package, the dependencies will remain on the system. This remaining package will no longer be used by anyone else and can be deleted.

To remove unnecessary dependencies, use the following command:

sudo apt autoremove

Package list (apt list)

The

list command allows you to list available, installed and upgradeable packages.

To list all available packages, use the following command:

[linuxmi@linux:~/www.linuxmi.com]$ sudo apt list

Learn Linux with me: apt command quick reference guide

This command will print a list of all packages, including information about the package's version and architecture. To determine whether a specific package is installed, you can use the grep command to filter the output.

sudo apt list | grep package_name

To list only installed packages, enter:

[linuxmi@linux:~/www.linuxmi.com]$ sudo apt list –installed

Learn Linux with me: apt command quick reference guide

Before actually upgrading a package, it may be useful to get a list of upgradeable packages, execute 'apt list --upgradable' to view them.

[linuxmi@linux:~/www.linuxmi.com]$ sudo apt list –upgradable

Learn Linux with me: apt command quick reference guide

Search package (apt search)

This command allows you to search for a given package in the list of available packages:

sudo apt search package_name

If found, the command will return packages whose names match the search term.

View software package information (apt show)

Before removing or installing a new package, information about package dependencies, installation size, package source, etc. may be useful.

To retrieve information about a given package, use the show command:

[linuxmi@linux:~/www.linuxmi.com]$ sudo apt show libgts-0.7-5

Learn Linux with me: apt command quick reference guide

Summarize

After studying this article, knowing how to manage software packages is an important part of Linux system management.

apt is a package manager based on debian distributions. To learn more about the apt command, open your terminal and type man apt.

The above is the detailed content of Learn Linux with me: apt command quick reference guide. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template