Updating Ubuntu
This guide explains how to update Ubuntu virtual machines running on Thalassa Cloud. Regular updates ensure your VMs receive security patches, bug fixes, and feature improvements.
Prerequisites
- SSH access to your Ubuntu virtual machine
- Root or sudo privileges
- Network connectivity for package downloads
Updating Ubuntu
Step 1: Update Package Lists
First, refresh the local package index to ensure you have the latest information about available packages:
sudo apt updateThis command downloads package information from all configured repositories.
Step 2: Upgrade Installed Packages
Upgrade all installed packages to their latest versions:
sudo apt upgradeReview the list of packages that will be upgraded. Type Y and press Enter to confirm.
For a more automated upgrade that doesn’t prompt for confirmation:
sudo apt upgrade -yStep 3: Perform Distribution Upgrade (Optional)
For major version upgrades (e.g., Ubuntu 22.04 to 24.04), use:
sudo apt full-upgradeThis command also handles dependency changes and may remove packages if necessary.
Step 4: Remove Unused Packages (Optional)
Clean up packages that are no longer needed:
sudo apt autoremoveThis removes packages that were automatically installed as dependencies but are no longer required.
Step 5: Clean Package Cache (Optional)
Free up disk space by removing cached package files:
sudo apt autocleanThis removes package files from the local cache that are no longer available in the repositories.
Automated Updates
For production environments, consider setting up unattended upgrades to automatically install security updates:
Install Unattended Upgrades
sudo apt install unattended-upgradesConfigure Unattended Upgrades
Edit the configuration file:
sudo nano /etc/apt/apt.conf.d/50unattended-upgradesEnable automatic updates for security patches by uncommenting:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-security";
};Enable Automatic Updates
sudo dpkg-reconfigure -plow unattended-upgradesSelect “Yes” when prompted to enable automatic updates.
Troubleshooting
Package Lock Errors
If you encounter “Unable to lock” errors:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lockThen retry the update command.
Broken Dependencies
Fix broken dependencies with:
sudo apt --fix-broken install