6.linux
apt
Commands

apt Commands Documentation

apt is a package management tool used in Debian-based systems (such as Ubuntu) for installing, upgrading, and removing software packages. Below are key commands for managing packages efficiently.

1. Update Package Index

Updates the local package index to ensure you get the latest versions of the available packages.

sudo apt update

2. Upgrade Installed Packages

Upgrades all the currently installed packages to their latest available versions.

sudo apt upgrade

3. List Installed Packages

Lists all the packages that are currently installed on the system.

apt list --installed

4. List Specific Installed Package

Filters the list of installed packages to show only the specified package.

apt list --installed | grep <package_name>

5. Install a Package

Installs a specified package and its dependencies. The -y flag automatically answers 'yes' to any prompts.

sudo apt install <pkg> -y

6. Download a Package Only

Downloads a package without installing it.

sudo apt install <pkg> --download-only

7. Remove a Package

Removes the specified package from the system. The -y flag automatically confirms the action.

sudo apt remove <pkg> -y

8. Purge a Package

Removes the specified package along with its configuration files.

sudo apt purge <pkg> -y

9. Search for a Package

Searches the package repository for a specific package by keyword.

apt search <keyword>

10. Show Package Information

Displays detailed information about a specific package, including its version, description, and dependencies.

apt show <pkg>

11. Clean Up Unused Packages

Removes unnecessary packages that were automatically installed but are no longer required.

sudo apt autoremove

12. Upgrade Distribution

Upgrades the distribution, including new packages and potential system upgrades.

sudo apt dist-upgrade

Bonus: Clean up and speed up your system

sudo apt autoremove # Removes unused packages sudo apt clean # Clears local repository of retrieved package files sudo apt autoclean # Removes outdated package files

This keeps your package cache clean and frees disk space. Got it! You want to download a .deb file from a URL and then install it. Here’s the full process in one go:


Step 1: Download the .deb file

Use wget or curl to download the file:

Using wget:

wget https://example.com/path/to/package_name.deb

Using curl:

curl -O https://example.com/path/to/package_name.deb

-O saves the file with its original name.


Step 2: Install the downloaded .deb

Option A – Using apt (recommended for dependencies):

sudo apt install ./package_name.deb

Option B – Using dpkg (manual dependency fix needed):

sudo dpkg -i package_name.deb
sudo apt-get install -f   # Fix missing dependencies

Step 3: Clean up (optional)

rm package_name.deb

Pro Tip: You can combine download and install in one line:

wget -O package_name.deb https://example.com/path/to/package_name.deb && sudo apt install ./package_name.deb

This will download the file and immediately install it.


Ah, perfect! If you have Postman as a .tar.gz file, you don’t install it via apt or dpkg—you extract it and run it directly. Here’s the step-by-step way:


Step 1: Move the .tar.gz file to a proper location

A common place is /opt:

sudo mv Postman-x.x.x-linux-x64.tar.gz /opt/
cd /opt

Replace Postman-x.x.x-linux-x64.tar.gz with your actual file name.


Step 2: Extract the archive

sudo tar -xzf Postman-x.x.x-linux-x64.tar.gz
  • This will create a Postman folder in /opt.

Step 3: Create a symbolic link for easy access

sudo ln -s /opt/Postman/Postman /usr/bin/postman
  • This allows you to launch Postman just by typing postman in the terminal.

Step 4: Run Postman

postman
  • Postman will start.

Step 5: Optional – Create a desktop shortcut

Create a .desktop file so Postman appears in your application menu:

sudo nano /usr/share/applications/postman.desktop

Add the following content:

[Desktop Entry]
Name=Postman
Comment=Postman API Client
Exec=/opt/Postman/Postman
Icon=/opt/Postman/app/resources/app/assets/icon.png
Terminal=false
Type=Application
Categories=Development;

Save (Ctrl+O) and exit (Ctrl+X). Now Postman will appear in your apps menu.