Apt get install command in linux

How to Use the Apt-Get Command in Linux

Home » SysAdmin » How to Use the Apt-Get Command in Linux

Every Linux user knows how critical apt-get commands are. From the very first time you install Ubuntu (or a similar Linux distribution), you come across this powerful tool.

This tutorial serves as a good introduction for beginners on the apt-get command. It can also help more experienced users refresh their memory and improve their knowledge of terminal commands.

What Is apt-get and What Is It Used For?

apt-get is a command line tool for interacting with the Advanced Package Tool (APT) library (a package management system for Linux distributions). It allows you to search for, install, manage, update, and remove software.

The tool does not build software from the source code. Instead, it compiles the source code or uses precompiled files to install software packages.

Along with apt-get , there is also the apt utility. To learn more about these commands check out the article on APT vs APT-GET differences.

Note: All these commands, except the apt-cache (search) command, only work within root or superuser (sudo) privileges.

apt-get Syntax

The main syntax for using apt-get commands is:

How to Use apt-get Command in Linux

Below you will find how to use the apt-get command to work with packages and software on your Linux system. Read through the list to learn more about the possibilities of apt-get .

How to Update or Upgrade Using apt-get

Before you install a package, it is crucial to resynchronize the package index files and update the package repository to the latest version. This ensures that the packages you install are up-to-date.

Update the package repository by running the command:

To update the package cache and checks for broken dependencies:

To upgrade all installed packages, use the apt-get command:

Upgrade a specific package by running:

Search for dependencies with newer versions, install new packages, and remove old ones automatically:

Note: Be careful when using dist-upgrade as it may remove some packages you still need on your system.

To follow the changes made to the Status field of available packages by the traditional Debian packaging tool dselect and perform actions necessary to realize that state, use the command:

How to Install Packages with apt-get

To install a package using apt-get , type in the following command:

Replace [package_name] with the name of the software package you intend to install. If you do not know the exact name of the package, type in the first few letters and press TAB. The system will suggest all the packages available, starting with those letters.

To install a specific version of a package, run:

Before the system installs the package, you will receive an output showing:

  • The additional packages required for the installation to be successful.
  • The package you intend to install.
  • The packages that must be upgraded.
  • How much disk space the package will use.

For example, if you want to install curl, you will receive the output as in the image below:

Finally, it will ask you whether you wish to continue with the installation. To answer, you must type in y for yes or n for no.

To install multiple packages at the same time with a single command:

If you have packages with many reverse dependencies and you need the most up-to-date versions, use the apt-get reinstall command.

To download a package with all required dependencies without installing by running:

How to Remove Packages with apt-get

To remove a package use the command:

However, this command only removes the package, leaving its configuration files on the system.

To remove the package along with its configuration files, use the command:

Читайте также:  Pdf24 виртуальный принтер настройка

To clean the local repository of retrieved package files, use the command:

The clean command removes everything except the local file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.

Another way to empty the local repository of retrieved files is to use autoclean and clear out packages that are no longer available:

To remove the unnecessary packages that apt-get automatically installs to satisfy dependencies for other packages, run the command:

How to Use apt-get Options

The apt-get command is modified by adding one or more options to the syntax.

Below you will find a list of all commonly used apt-get options.

  • —no-install-recommends – only install main dependencies, do not include recommended packages
  • —install-suggests – install suggested packages as dependencies
  • -d/—download-only – download the packages without installing or unpacking them
  • -f/—fix-broken – attempt to correct a system with broken dependencies
  • -m/—ignore-missing/—fix-missing – ignore packages that cannot be retrieved
  • —ignore-hold – ignore packages placed on hold
  • —no-download – disable downloading packages
  • -q/—quiet – omit progress indicators and produce output suitable for logging
  • -s/—simulate/—just-print/—dry-run,—recon,—no-act — simulate events that would occur without actually change the system
  • -y/—yes/—assume-yes – assume «yes» as an answer to prompts
  • —assume-no — assume «no» as an answer to all prompts
  • —no-upgrade – do not upgrade packages (usually used with the install command to instruct apt-get not to upgrade if the package is already installed)
  • —only-upgrade – upgrade only installed packages
  • -V/—verbose-versions – display full versions of upgraded and installed packages
  • —show-progress – display progress bar while installing, removing or upgrading packages
  • >-b/—compile/—build – compile source packages once downloaded
  • —only-upgrade – upgrade only installed packages
  • —reinstall – reinstall installed packages to the newest version
  • —auto-remove/—autoremove — remove unnecessary packages while installing a package
  • -h/—help – display a short usage summary
  • -v/—version – display the version of apt-get
  • -c/—config-file – specify which configuration file to read after the default one
  • -o/—option – set an arbitrary configuration option

You can also define custom options by modifying the configuration file.

In this article, you learned the most common apt-get and apt-cache commands. These commands are simple to use and easy to remember.

Once you have mastered the use of each command, you can manage all your packages with ease and confidence.

Источник

Ubuntu Documentation

This article applies to all supported versions of Ubuntu

Package management via apt-get runs hand-in-hand with the /etc/apt/sources.list file. For information on editing or updating your sources list see SourcesList.

Introduction

This page describes how to handle the packages on your system using apt-get and related commands. For example, you can install a new package, remove an installed package, or update all installed packages to the latest versions.

Commands

All these commands except the search commands must be run as root or with superuser privileges, see sudo for more information.

Example:

Installation commands

    This command installs a new package.

This command searches the repositories and installs the build dependencies for

. If the package is not in the repositories it will return an error.

Aptitude is an Ncurses viewer of packages installed or available. Aptitude can be used from the command line in a similar way to apt-get. Enter man aptitude for more information.
APT and aptitude will accept multiple package names as a space delimited list. For example:

Use the -s flag to simulate an action. For example: «apt-get -s install

» will simulate installing the package, showing you what packages will be installed and configured.

auto-apt

This command runs under the control of auto-apt. If a program tries to access a file known to belong in an uninstalled package, auto-apt will install that package using apt-get. This feature requires apt and sudo to work.

  • Auto-apt keeps databases which need to be kept up-to-date in order for it to be effective. This is achieved by calling the commands auto-apt update, auto-apt updatedb and auto-apt update-local.
  • Usage example

    You’re compiling a program and, all of a sudden, there’s an error because it needs a file you don’t have. The program auto-apt asks you to install packages if they’re needed, stopping the relevant process and continuing once the package is installed. It will then ask to install the needed packages and call apt-get automatically. If you’re running X, a graphical interface will replace the default text interface.

    Читайте также:  Как установить дрова на принтер на windows 7

    Maintenance commands

    Run this command after changing /etc/apt/sources.list or /etc/apt/preferences . For information regarding /etc/apt/preferences, see PinningHowto. Run this command periodically to make sure your source list is up-to-date. This is the equivalent of «Reload» in Synaptic or «Fetch updates» in Adept.

  • This command upgrades all installed packages. This is the equivalent of «Mark all upgrades» in Synaptic.
  • The same as the above, except add the «smart upgrade» checkbox. It tells APT to use «smart» conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary.

    «apt-get dist-upgrade» does not upgrade from a previous version of Ubuntu. For more information of upgrading from a previous version of Ubuntu see http://www.ubuntu.com/getubuntu/upgrading .

    This command does the same thing as Edit->Fix Broken Packages in Synaptic. Do this if you get complaints about packages with «unmet dependencies».

    This command removes .deb files for packages that are no longer installed on your system. Depending on your installation habits, removing these files from /var/cache/apt/archives may regain a significant amount of diskspace.

    The same as above, except it removes all packages from the package cache. This may not be desirable if you have a slow Internet connection, since it will cause you to redownload any packages you need to install a program.

    The package cache is in /var/cache/apt/archives . The command will tell you how much space cached packages are consuming.

    Reconfigure the named package. With many packages, you’ll be prompted with some configuration questions you may not have known were there.

      For example: will present you with a «wizard» on configuring fonts in Ubuntu.

    This command places the desired package on hold. TODO: Bug #42178: This is the same as Synaptic’s Package->Lock Version. */

    This command may have the unintended side effect of preventing upgrades to packages that depend on updated versions of the pinned package. apt-get dist-upgrade will override this, but will warn you first. If you want to use this command with sudo, you need to use echo "

    hold" | sudo dpkg --set-selections not sudo echo "

    hold" | dpkg --set-selections.

    Removal commands

    • This command removes an installed package, leaving configuration files intact.
    • This command completely removes a package and the associated configuration files. Configuration files residing in

    are not usually affected by this command.

      + operator

      If you want to remove package1 and install package2 in one step: .

  • This command removes packages that were installed by other packages and are no longer needed.
    • This command removes an installed package and dependencies.

    While there is no built in way to remove all of your configuration information from your removed packages you can remove all configuration data from every removed package with the following command.

    Search commands

    Each package has a name and a description. This command lists packages whose name or description contains .

    This will find packages whose names contain . Similar to apt-cache search, but also shows whether a package is installed on your system by marking it with ii (installed) and un (not installed).

    This command shows the description of package

    and other relevant information including version, size, dependencies and conflicts.
    This command is similar to «apt-cache show».

    This command will list files in package

    This command lists files in the package «foo.deb». Note that foo.deb is a pathname. Use this command on .deb packages that you have manually downloaded.

    This command determines which installed package owns

    . It shows files from installed packages that match

    , with the name of the package they came from. Consider this to be a «reverse lookup» utility.

    In order to use this command, the package dlocate must be installed on your system.

    This command does the same as dlocate, but does not require the installation of any additional packages. It is slower than dlocate but has the advantage of being installed by default on all Debian and Ubuntu systems.

    This command acts like dlocate and dpkg -S, but searches all available packages. It answers the question, «what package provides this file?».

    apt-file needs to be updated regularly like apt-get. Use the command:

    In order to use this command, the package apt-file must be installed on your system.

    A general note on searching: If searching generates a list that is too long, you can filter your results by piping them through the command grep. Examples:

    will show only the files that contain as a whole word

  • will list files located in the directory /usr/bin, useful if you’re looking for a particular executable.
  • For more information on apt-get, apt-cache and dpkg consult their manual pages by using the man command. These manuals will provide a wider scope of information in addition to all of the options that you can use with each program.

    Example: .

    Typical usage example

    I want to feel the wind in my hair, I want the adrenaline of speed. So let’s install a racing game. But what racing games are available?

    It gives me a lot of answers. I see a game named «torcs». Let’s get some more information on this game.

    Hmmm. it seems interesting. But is this game not already installed on my computer? And what is the available version? Which repository is it from (Universe or Main)?

    Ok, so now, let’s install it!

    What is the command I must type in the console to launch this game? In this example, it’s straightforward («torcs»), but that’s not always the case. One way of finding the name of the binary is to look at what files the package has installed in «/usr/bin». For games, the binary will be in «/usr/games». For administrative programs, it’s in «/usr/sbin».

    The first part of the command display all files installed by the package «torcs» (try it). With the second part, we ask to only display lines containing «/usr/games/».

    Hmmm, that game is cool. Maybe there are some extra tracks?

    But I’m running out of space. I will delete the apt cache!

    Oh no, my mother asked me to remove all games from this computer. But I want to keep the configuration files so I can simply re-install it later.

    If I want to also remove config files :

    Setting up apt-get to use a http-proxy

    These are three methods of using apt-get with a http-proxy.

    Temporary proxy session

    This is a temporary method that you can manually use each time you want to use apt-get through a http-proxy. This method is useful if you only want to temporarily use a http-proxy.

    Enter this line in the terminal prior to using apt-get (substitute your details for yourproxyaddress and proxyport).

    If you normally use sudo to run apt-get you will need to login as root first for this to work unless you also add some explicit environment settings to /etc/sudoers, e.g.

    APT configuration file method

    This method uses the apt.conf file which is found in your /etc/apt/ directory. This method is useful if you only want apt-get (and not other applications) to use a http-proxy permanently.

    On some installations there will be no apt-conf file set up. This procedure will either edit an existing apt-conf file or create a new apt-conf file.

    Add this line to your /etc/apt/apt.conf file (substitute your details for yourproxyaddress and proxyport).

    Save the apt.conf file.

    BASH rc method

    This method adds a two lines to your .bashrc file in your $HOME directory. This method is useful if you would like apt-get and other applications for instance wget, to use a http-proxy.

    Add these lines to the bottom of your

    /.bashrc file (substitute your details for yourproxyaddress and proxyport)

    Save the file. Close your terminal window and then open another terminal window or source the

    Test your proxy with sudo apt-get update and whatever networking tool you desire. You can use firestarter or conky to see active connections.

    If you make a mistake and go back to edit the file again, you can close the terminal and reopen it or you can source

    /.bashrc as shown above.

    How to login a proxy user

    If you need to login to the Proxy server this can be achieved in most cases by using the following layout in specifying the proxy address in http-proxy. (substitute your details for username, password, yourproxyaddress and proxyport)

    Источник

    Поделиться с друзьями
    КомпСовет
    Adblock
    detector