Managing software is a fundamental skill for any Ubuntu Server administrator. Whether you’re working in a cloud environment like Azure, AWS, or GCP, or managing on-premises infrastructure, understanding package management tools such as APT is essential for maintaining a secure and optimized system.
In this guide, we’ll cover the basics of installing, updating, and managing software, explore cloud-specific scenarios, troubleshoot common issues, and provide practical examples to help you master Ubuntu Server administration.

Table of Contents
- Understanding APT and Package Management on Ubuntu
- Installing Software with APT
- Removing Software
- Updating and Upgrading Packages
- Managing Repositories
- Managing Package Cache
- Cloud Scenarios: Software Management in Azure, AWS, and GCP
- Troubleshooting Common Issues During Installation or Uninstallation
- Best Practices for Package Management
1. Understanding APT and Package Management on Ubuntu
Ubuntu Server uses APT (Advanced Package Tool) as its primary package manager. APT simplifies software management by handling dependencies automatically and using repositories as trusted sources for packages.
Key Components of APT:
- apt: Command-line tool for managing packages.
- dpkg: Low-level package manager for
.deb
files. - Repositories: Online sources where Ubuntu packages are stored and retrieved.
2. Installing Software with APT
To install software on Ubuntu Server, use the apt install
command.
Example: Installing Apache Web Server
- Update the package list:
sudo apt update
Output:
Hit:1 http://azure.archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://azure.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Get:3 http://azure.archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
Get:4 http://azure.archive.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Get:5 http://azure.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [922 kB]
Get:6 http://azure.archive.ubuntu.com/ubuntu noble-updates/main amd64 Components [151 kB]
Get:7 http://azure.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Components [364 kB]
Get:8 http://azure.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Components [212 B]
Get:9 http://azure.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Components [940 B]
Get:10 http://azure.archive.ubuntu.com/ubuntu noble-backports/main amd64 Components [7076 B]
Get:11 http://azure.archive.ubuntu.com/ubuntu noble-backports/universe amd64 Components [21.3 kB]
Get:12 http://azure.archive.ubuntu.com/ubuntu noble-backports/restricted amd64 Components [212 B]
Get:13 http://azure.archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 Components [212 B]
Get:14 http://azure.archive.ubuntu.com/ubuntu noble-security/main amd64 Components [9024 B]
Get:15 http://azure.archive.ubuntu.com/ubuntu noble-security/universe amd64 Components [51.9 kB]
Get:16 http://azure.archive.ubuntu.com/ubuntu noble-security/restricted amd64 Components [208 B]
Get:17 http://azure.archive.ubuntu.com/ubuntu noble-security/multiverse amd64 Components [208 B]
Fetched 1907 kB in 1s (2778 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
15 packages can be upgraded. Run 'apt list --upgradable' to see them.
- Install Apache:
sudo apt install apache2
3. Removing Software
If you no longer need a package, you can remove it using the apt remove
or apt purge
commands.
Example: Removing Apache
sudo apt remove apache2
Output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
apache2
...
After this operation, 2 MB disk space will be freed.
Do you want to continue? [Y/n]
To remove it completely, including configuration files:
sudo apt purge apache2
4. Updating and Upgrading Packages
Regular updates are critical for system security and stability.
Commands:
- Update the Package List
sudo apt update
- Upgrade Installed Packages
sudo apt upgrade
- Full Upgrade (Including Kernel Updates)
sudo apt full-upgrade
Output:
The following packages will be upgraded:
linux-image-5.4.0-91-generic linux-headers-5.4.0-91-generic ...
Do you want to continue? [Y/n]
5. Managing Repositories
Repositories are essential for package management. By default, Ubuntu uses official repositories, but additional repositories can be added, modified, or removed as needed.
Managing Repositories in Deb822 Format
Recent versions of Ubuntu have transitioned to the Deb822 format for repository management. Instead of using the traditional /etc/apt/sources.list
file, repositories are now managed through .sources
files located in the /etc/apt/sources.list.d/
directory.
Viewing Current Repositories
To view your current repositories, check the .sources
files in /etc/apt/sources.list.d/
:
ls /etc/apt/sources.list.d/
For example:
cat /etc/apt/sources.list.d/ubuntu.sources
A .sources
file in Deb822 format looks like this:
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Adding a Repository
To add a new repository in Deb822 format, create a .sources
file in /etc/apt/sources.list.d/
. For example, to add a custom PPA repository:
sudo nano /etc/apt/sources.list.d/custom.sources
Add the desired customized content:
Types: deb
URIs: http://customizedurl/
Suites: noble
Components: main
Signed-By: /usr/share/keyrings/repository-name.gpg
Save the file and update the package list:
sudo apt update
Removing a Repository
To remove a repository, delete the corresponding .sources
file from /etc/apt/sources.list.d/
:
sudo rm /etc/apt/sources.list.d/custom.sources
sudo apt update
Benefits of Deb822 Format
- Structured Configuration: Clearly separates repository types, URIs, suites, and components.
- Improved Security: Allows specifying GPG keys for repository signing using the
Signed-By
field. - Better Compatibility: Easier to manage multiple repositories in cloud and containerized environments.
For more details, refer to the sources.list(5) manual page.
6. Managing Package Cache
APT uses a cache system to store downloaded package files and metadata locally. This cache helps speed up operations like software installation and updates but can grow over time and consume disk space. Understanding how to manage the cache is essential for maintaining system performance and freeing up resources.
Checking the Cache Size
To check how much space the cache is using:
sudo du -sh /var/cache/apt/
Output Example:
126M /var/cache/apt/
Cleaning the Cache
- Clear the Package Cache
Use theapt clean
command to remove all cached package files:sudo apt clean
This clears the/var/cache/apt/archives
directory, which stores downloaded.deb
files. - Remove Partial Downloads
If a download was interrupted or corrupted, remove partial files with:sudo apt autoclean
This only removes outdated files and partial downloads.
Example Output for Cache Cleanup
sudo apt clean
sudo apt autoclean
Output:
Cleaning up /var/cache/apt/archives...
Removing unused files...
Done.
Rebuilding the Cache
If you suspect the cache metadata is corrupted, rebuild it by updating the package list:
sudo apt update
This refreshes the local cache with the latest metadata from repositories.
7. Cloud Scenarios: Software Management in Azure, AWS, and GCP
In cloud environments, software management on Ubuntu Server works similarly to on-premises setups. However, there are additional considerations:
Azure
- Azure provides Custom Script Extensions to automate software installation during VM deployment.
- Example: Using a script to install Nginx:
az vm extension set \
--resource-group myResourceGroup \
--vm-name myVM \
--name CustomScript \
--publisher Microsoft.Azure.Extensions \
--settings '{"commandToExecute":"sudo apt update && sudo apt install -y nginx"}'
AWS
- Use User Data Scripts to install software during instance launch.
- Example: Installing Docker on an EC2 instance:
#!/bin/bash
sudo apt update
sudo apt install -y docker.io
GCP
- Use Startup Scripts to manage software installation on VM instances.
- Example: Installing MySQL:
#!/bin/bash
sudo apt update
sudo apt install -y mysql-server
8. Troubleshooting Common Issues During Installation or Uninstallation
1. Package Not Found
If a package isn’t found, ensure the repository is enabled:
sudo apt update
2. Dependency Errors
Fix missing dependencies:
sudo apt --fix-broken install
3. Repository Issues
Check for repository errors:
sudo apt update
Output Example:
Err:1 http://ppa.launchpad.net/repository-name/ubuntu noble Release
404 Not Found
Solution: Remove or fix the repository entry in /etc/apt/sources.list
.
4. Uninstallation Leaves Residual Files
Clean up leftover files:
sudo apt autoremove
sudo apt purge package-name
5. Permission Denied
Ensure you have root privileges:
sudo apt install package-name
9. Best Practices for Package Management
- Always Update Before Installing Software
sudo apt update
- Regularly Upgrade Your System
Useapt upgrade
orapt full-upgrade
to keep your system secure. - Remove Unnecessary Packages
sudo apt autoremove
- Use Trusted Repositories
Avoid third-party repositories unless necessary. - Monitor Package Changes in Cloud Environments
Automate updates using scripts or configuration management tools like Ansible. - Clean the Cache Periodically
Clear the cache regularly to free up disk space:sudo apt clean
Conclusion
Whether you’re managing an on-premises server or working in the cloud, mastering software installation and management on Ubuntu Server is critical for maintaining a secure and efficient system. By following the best practices outlined in this guide, you can ensure your server remains optimized and ready for any workload.
For more information, refer to the official Ubuntu documentation on APT.
What’s Next?
In the next article, we’ll dive deeper into patching and updating Ubuntu Server, a critical task for maintaining security and stability. You’ll learn:
- Why patching is critical for security and stability and how it prevents vulnerabilities.
- How to use apt to update and upgrade your server effectively.
- The differences between apt update, apt upgrade, and apt full-upgrade to avoid common mistakes.
- Automating updates with unattended-upgrades to save time and ensure consistency.
- How to handle kernel updates and reboot your server gracefully using reboot-required notifications.
Stay tuned for actionable insights on keeping your Ubuntu Server secure and up-to-date!