apt Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
The Advanced Packaging Tool, apt command in Linux, is a powerful command-line tool used for handling packages in Ubuntu/Debian-based systems. It provides powerful, consistent command-line interfaces for package management and takes care of dependencies automatically.
Syntax of apt Command in Linux
The basic syntax of the apt command in Linux is as follows:
Where:
- options: Options are the optional flags that can be used with the apt command to modify its behavior. For example, '-y' is used to answer 'yes' to all prompts.
- command: This is the action you want to perform, such as install, remove, upgrade, etc.
Options in apt Command in Linux
-
-y: This option is used to answer 'yes' to all prompts during the operation.
For example -
Output:
The '-y' option instructs apt to proceed with all actions without asking for confirmation.
-
--show-progress: This option is used to display the progress during the operation.
For example -
Output:
The '--show-progress' option makes apt show a progress indicator during the operation.
-
--fix-broken: This option attempts to correct a system with broken dependencies in place.
For example -
Output:
The '--fix-broken' option commands apt to try and fix unresolved dependencies.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example Usages
-
Installing a package.:
Output:
Explanation: The 'install' command is used to install a new package, in this case, Vim text editor.
-
Upgrading all upgradable packages.:
Output:
Explanation: The 'upgrade' command upgrades all the upgradable packages in the system.
Tips
-
Always use 'sudo apt update' before 'sudo apt upgrade' to ensure your package lists are up-to-date.
-
Use 'sudo apt autoremove' to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.
Turn Learning into Career Growth
Advanced Use Cases of apt Command in Linux
-
Use 'dist-upgrade' command to intelligently handle changing dependencies.:
Output:
Explanation: The 'dist-upgrade' command will upgrade your system by handling changing dependencies with new versions of packages.
-
Use 'full-upgrade' command which performs the function of upgrade but also removes installed packages if needed.:
Output:
Explanation: The 'full-upgrade' command performs the same function as 'upgrade' but will remove currently installed packages if necessary.
-
Hold a package using 'hold' command to prevent it from being automatically installed, upgraded or removed.:
Output:
Explanation: The 'hold' command is used to mark a package to hold back its installation or upgrade.
Conclusion
-
The apt command in Linux is a powerful tool for managing packages in Ubuntu and Debian-based systems.
-
It simplifies the process of installing, upgrading, and removing software packages.
-
Advanced options and commands allow fine-grained control over your system's software packages and dependencies.