0
0
Linux-cliHow-ToBeginner · 3 min read

How to Install a Package in Ubuntu Using apt

To install a package in Ubuntu, use the apt install package-name command in the terminal. First, update your package list with apt update to get the latest versions.
📐

Syntax

The basic command to install a package in Ubuntu is:

  • sudo apt update: Refreshes the list of available packages and their versions.
  • sudo apt install package-name: Installs the specified package.

Use sudo to run the command with administrator rights.

bash
sudo apt update
sudo apt install package-name
💻

Example

This example shows how to install the curl package, a tool to transfer data from or to a server.

bash
sudo apt update
sudo apt install curl
Output
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: curl 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 159 kB of archives. After this operation, 500 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 curl amd64 7.68.0-1ubuntu2.7 [159 kB] Fetched 159 kB in 1s (200 kB/s) Selecting previously unselected package curl. (Reading database ... 123456 files and directories currently installed.) Preparing to unpack .../curl_7.68.0-1ubuntu2.7_amd64.deb ... Unpacking curl (7.68.0-1ubuntu2.7) ... Setting up curl (7.68.0-1ubuntu2.7) ... Processing triggers for man-db (2.9.1-1) ...
⚠️

Common Pitfalls

Common mistakes when installing packages include:

  • Not running sudo apt update first, which can cause installation of outdated packages or failure.
  • Typing the wrong package name, resulting in an error like Unable to locate package.
  • Not having administrator rights, causing permission denied errors.

Always check the package name and run update before install.

bash
sudo apt install curl
# Wrong: missing sudo
apt install curl
# Wrong: misspelled package
sudo apt install crul
Output
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root? Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package crul
📊

Quick Reference

CommandDescription
sudo apt updateRefresh package list
sudo apt install package-nameInstall a package
sudo apt remove package-nameRemove a package
apt search keywordSearch for packages
apt show package-nameShow package details

Key Takeaways

Always run 'sudo apt update' before installing packages to get the latest list.
Use 'sudo apt install package-name' to install software with administrator rights.
Check the package name carefully to avoid errors.
Lack of 'sudo' causes permission denied errors.
Use 'apt search' to find the correct package name if unsure.