Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
aptitude command in Linux with examples
Next article icon

apt-get command in Linux with Examples

Last Updated : 17 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The command-line tool `apt-get` is the most popular package management tool used in our Debian-based Linux operating system. This article provides an overview of `apt-get` and its basic syntax. It will include the most commonly used commands, their syntax, description, and examples. It also gives an explanation of the contrast to other Linux distributions such as CentOS and Fedora, which use different package managers, and Debian-based Linux distributions use APT (Advanced Packaging Tool).

What is apt-get?

apt-get is a command-line tool that helps in handling packages in Linux. Its main task is to retrieve the information and packages from the authenticated sources for installation, upgrade, and removal of packages along with their dependencies. Here APT stands for Advanced Packaging Tool. It is a Debian-based Linux operating system, for example, Ubuntu and Debian itself. It is an APT (Advance Packaging Tool) system. Which manages packages for Debian-based Linux distributions.

What is Debian-based Linux distributions?

A family of operating systems that are built on the Debian operating system. They use the same APT (Advance Packaging Tool) for package management system. Some of the most popular Debian-based Linux distributions have different features but come under the same underlying Debian system and package management tools are Linux Mint, Ubuntu and kali Linux. 

One must know when we talk about Red Hat-based distributions like CentOS and Fedora, they are Linux distributions but not Debian-based Linux distributions. Red Hat-based Linux distributions are often preferred for enterprise environments and servers, focusing on stability and security. Whereas Debian-based Linux distributions moreover focus on long-term support and stability.

Note: apt-get (package manager) is used in Debian-based Linux distributions but in Linux distributions like CentOS and Fedora uses different package manager.

APT-GET Command in Linux

Basic Syntax: 

sudo apt-get [options] [command] [package(s)]

Breakdown of each component:

  • ` sudo `: We will be using ‘sudo’ before every ‘apt-get’ command because ‘sudo’ in Linux system is used to execute command with the administrative privileges (root privileges). In the case of ‘apt-get’ which is used to manage software packages on Debian-based Linux systems, we need administrative privileges to install, remove, update and make other changes.
  • `apt-get`: The command itself.
  • `[options]`: This is an optional parameter in this we can use `-y` or `-s` for modifying the behavior of `apt-get` command. `-y` is for automatically answering “yes” and `-s` is for simulating a command without making any changes.
  • `[packages]`: In this we specify the package that we want to remove, upgrade or install. If we want to mention multiple packages at same time, specify them by separated spaces between them.

Most Used Commands[APT-GET]

You need to provide one of the commands below, if the -h option is not used.

Commands Description Syntax Example
update                                                                                                                           Used in Linux-based operating systems to update the package lists for available software packages from the configured repositories. sudo apt-get update                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        sudo apt-get update                                                                                                                                                                                                                                                                                                                                                                                                                                          
upgrade              This command is used to install the latest versions of the packages currently installed on the user’s system from the sources enumerated in /etc/apt/sources.list. The installed packages which have new packages available are retrieved and installed. You need to perform an update before the upgrade so that apt-get knows that new versions of packages are available. sudo apt-get upgrade sudo apt-get upgrade
dselect-upgrade The command used in Linux-based operating systems to upgrade the system by installing and removing packages according to the selections made in the `dselect`. sudo apt-get dselect-upgrade sudo apt-get dselect-upgrade
dist-upgrade This command performs the function of upgrade, and also handles changing dependencies with new versions of packages. If necessary, the apt-get command will try to upgrade important packages at the expense of less important ones. It may also remove some packages in this process. sudo apt-get dist-upgrade
 
sudo apt-get dist-upgrade
 
install This command is used to install or upgrade packages. It is followed by one or more package names the user wishes to install. All the dependencies of the desired packages will also be retrieved and installed. The user can also select the desired version by following the package name with an ‘equal’ and the desired version number. Also, the user can select a specific distribution by following the package name with a forward slash and the version or the archive name (e.g., ‘stable’, ‘testing’, or ‘unstable’). Both of these version selection methods have the potential to downgrade the packages, so they must be used with care. sudo apt-get install [package_name]
 
sudo apt-get install vim
 
reinstall If we already have a package but we want to reset it to its default state, we can re-install that package.  sudo apt-get install –reinstall [package_name]
 
sudo apt-get install –reinstall firefox
 
remove This is similar to install, with the difference being that it removes the packages instead of installing. It does not remove any configuration files created by the package. sudo apt-get remove [package_name]
 
sudo apt-get remove vim
 
purge This command removes the packages, and also removes any configuration files related to the packages. sudo apt-get purge [package_name]
 
sudo apt-get purge vim
 
check This command is used to update the package cache and check for broken dependencies. sudo apt-get check
 
sudo apt-get check
 
download This command is used to download the given binary package in the current directory. sudo apt-get download [package_name]
 
sudo apt-get download firefox
 
clean This command is used to keep our system clean and tidy. It removes all the cached package files that were downloaded due to the downloading of recent packages using `apt-get`. sudo apt-get clean
 
sudo apt-get clean
 
autoremove Sometimes the packages which are automatically installed to satisfy the dependencies of other packages, are no longer needed then the autoremove command is used to remove this kind of packages. sudo apt-get autoremove
 
sudo apt-get autoremove
 
source If we want to recompile or modify the source code of a package. Source code will be downloaded in current directory in tarball format. sudo apt-get source [package_name]
 
sudo apt-get source firefox
 
show If we want to know more about a package, verify its installation status, version, description, other metadata and dependencies.  sudo apt-get show [package_name]
 
sudo apt-get show firefox
 
list It also gives details (version, architecture and repository source) about package but only if package is available or installed in our system. 

sudo apt-get list
             “or”

 sudo apt-get list [package_name]
 

sudo apt-get list firefox
 

Options Available in `apt-get`:

Options Description  Syntax Example
–no-install-recommends                                                                                                                                                                                                                                                                                                                                                                                                        It will avoid downloading any kind of recommended packages that are not strictly required by the package (installed/upgraded/reinstalled/installed). One must be caution while using this because there may be some package needed for your requirement.                                               sudo apt-get –no-install-recommends [Command] [package_name]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                                     
sudo apt-get –no-install-recommends install firefox                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
 
–install-suggests It works opposite of `–no-install-recommends`. It downloads all the suggested packages that are not required much.  sudo apt-get –install-suggests [Command] [package_name]
 
sudo apt-get –install-suggests install firefox
 
-d or –download-only In this package is only downloaded in the location (`/var/cache/apt/archives/`) by default, it is not installed, we can further in future install it. sudo apt-get -d [command] [package_name]
 
sudo apt-get -d install vlc
 
-f or –fix-broken By passing this option, the user specifies that apt-get should attempt to correct the system with broken dependencies in place. sudo apt-get -f install
 
sudo apt-get -f install
 
-m or –ignore-missing or –fix-missing By passing this option, the user specifies that apt-get should ignore the missing packages (packages that cannot be retrieved or fail the integrity check) and handle the result. sudo apt-get -m install [package_name]
 
sudo apt-get -m install apache2
 
–no-download In this `apt-get` is instructed to download packages already available in cache, not to download any package from configured package sources. sudo apt-get –no-download install [package_name]
 
sudo apt-get –no-download install vim
 
-q or –quiet This is used to silence the output errors or displaying warning messages. It is useful while writing scripts. sudo apt-get -q install [package_name]
 
sudo apt-get -q install apache2
 
       
-s or –simulate or –just-print or –dry-run or –recon or –no-act In this package in not actually installed, it just shows what operations it will perform while installing that package. sudo apt-get -s install [package_name]
 
sudo apt-get -s install firefox
 
-y or –yes or –assume-yes It automatically promotes yes while installing a package if there is any request or conformation that has to be taken from user, but one should be careful while using this. sudo apt-get -y [command] [package_name]
 
sudo apt-get -y install vim
 
–assume-no It automatically passes no to any question that will arise during the installation of any package. sudo apt-get –assume-no install [package_name]
 
sudo apt-get –assume-no install apache2
 
–no-show-upgraded Used to suppress the list of upgraded packages that is normally displayed at the end of the upgrade process. (Only works on upgrade command don’t work on install, remove or purge etc). sudo apt-get –no-show-upgraded upgrade
 
sudo apt-get –no-show-upgraded upgrade
 
-V or –verbose-versions Used to display the version number of all the available packages including those that are not even installed. (Only work on update command, not on any other like upgrade, install, remove or purge etc) sudo apt-get -V update
 
sudo apt-get -V update
 
–show-progress Used to display a bar for the progress of the command. (Only used for update command and has no effect on commands like upgrade, install, remove or purge etc) sudo apt-get –show-progress update
 
sudo apt-get –show-progress update
 
-b or –compile or –build build-dep is used to install the build dependencies of the specified packages and `-b` is used to build a package from source.

sudo apt-get build-dep [package_name]

              “or”
sudo apt-get -b source [package_name]
 

sudo apt-get build-dep firefox

                     “or”
sudo apt-get -b source vlc
 

–no-upgrade It is to install a package without upgrading to a new version. (Only works with install command) sudo apt-get install [package_name] –no-upgrade
 
sudo apt-get install vim –no-upgrade
 
–only-upgrade It upgrades the package to the newer version while stopping the installation of other packages from being upgraded during the update process. sudo apt-get install –only-upgrade [package_name]
 
sudo apt-get install –only-upgrade firefox
 
–reinstall It reinstalls the package, even if the package is installed.  sudo apt-get install –reinstall [package_name]
 
sudo apt-get install –reinstall firefox
 
-h or –help It is used to display a help manual. apt-get –help
 
apt-get –help
 

Note: apt-get command will return 0 for successful executions, and decimal 100 in case of errors.

sudo apt-get update

UPDATE

Syntax for `apt-get upgrade`:

In this we going to upgrade firefox,  if it is already upgrade it will show firefox is already upgraded.

sudo apt-get upgrade
sudo apt-get upgrade

UPGRADE

Not able to run `apt-get` in Red Hat Linux?

`apt-get` it is command used for package management but only in Debian-based Linux distributions like mint, Debian and ubuntu, whereas Red Hat Linux is a Linux distribution but does not come under Debian-based Linux distributions. Red Hat Enterprise Linux (RHEL), Fedora and CentOS all will not be able to use `apt-get` instead we can use `dnf` or `yum` package management tools. Just for basic example: we can use `sudo yum update` or `sudo dnf update`.

How to install packages using `apt-get` command?

In this we are going to install firefox package in our Debian-base Linux operating system (In this case we are executing this command in Ubuntu)

Syntax for `apt-get install`:

sudo apt-get install firefox

Installed Packages



Next Article
aptitude command in Linux with examples
author
rossoskull
Improve
Article Tags :
  • Linux-Unix
  • Linux-basic-commands
  • linux-command

Similar Reads

  • accton command in Linux with Examples
    'accton' is one of important Linux/Unix command which is used by the administrator to monitor user activities. It is used to turn on or turn off the process for accounting or change the info process accounting file. When the command is run in the terminal without any argument, it stops the process a
    2 min read
  • aclocal command in Linux with Examples
    aclocal command in Linux is used to automatically generate 'aclocal.m4' files from configure.in file. automake in Linux contain a lot of autoconf macros that can be used in the different packages. These macros must be defined in the aclocal.m4. If not, then it can’t be accessed by the autoconf. The
    3 min read
  • ACPI command in Linux with examples
    ACPI is the command in Linux that helps the users in managing power settings. It also helps in monitoring the hardware status efficiently. It facilitates with providing essential information such as battery health, CPU temperatures, and fan speeds, providing support in system maintenance and perform
    4 min read
  • acpi_available command in Linux with examples
    acpi_available is a command in Linux that tests whether the ACPI (Advanced Configuration and Power Interface) subsystem is available or not. Syntax$ acpi_availableReturn Statuses of acpi_availableThe command returns one of three possible statuses: Status 0: Indicates that the ACPI subsystem is avail
    2 min read
  • acpid command in Linux with Examples
    The acpid daemon provides intelligent power management on a system and allows to query battery and configuration status by supporting the Advanced Configuration and Power Interface (ACPI). The ACPI events are notified to the user-space programs by acpid. The ACPI (Advanced Configuration and Power In
    3 min read
  • addr2line command in Linux with Examples
    'addr2line' command in Linux is used to convert addresses into file names and line numbers. When the executable files/object files are run with the 'objdump' command, the file is de-assembled and the machine code is displayed. These machine instructions for the executable are displayed along with th
    4 min read
  • agetty command in Linux with Examples
    agetty is a Linux version of getty. getty short for "get tty" is a Unix program running on a host computer that manages physical or virtual terminals to allow multi-user access. Linux provides a virtual terminal(tty) which is similar to the regular Linux terminal. agetty command opens a virtual term
    4 min read
  • How to Create and Use Alias Command in Linux
    Imagine you're lost in a maze of complicated Linux commands. You stumble upon a secret doorway marked "Alias," and inside you find shortcuts to all your favorite commands! That's what creating aliases is like. You get to make your own mini-commands for the long ones you use all the time, making thin
    6 min read
  • amixer command in Linux with Examples
    amixer is a command-line mixer for ALSA(Advanced Linux Sound Architecture) sound-card driver . amixer can support multiple soundcards. amixer with no arguments will display the current mixer settings for the default soundcard as well as the device. This is a good way to see a list of the simple mixe
    2 min read
  • aplay command in Linux with examples
    aplay is a command-line audio player for ALSA(Advanced Linux Sound Architecture) sound card drivers. It supports several file formats and multiple soundcards with multiple devices. It is basically used to play audio on command-line interface. aplay is much the same as arecord only it plays instead o
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences