How to Update Raspbian on a Raspberry Pi
Learn how to safely update Raspbian packages on a Raspberry Pi with apt-get, check disk space, handle prompts, and verify whether a reboot is needed.
Regular updates keep a Raspberry Pi's software current. This guide shows the standard command-line workflow: check connectivity and storage, refresh package information, and upgrade installed packages.
Raspbian is the Raspberry Pi-focused Linux distribution name historically used for the operating system now commonly known as Raspberry Pi OS. The commands in this guide use APT, the Debian-family package management system used to obtain and maintain software packages.
Why update Raspbian regularly?
Updates provide newer package versions, bug fixes, stability improvements, and security fixes. Keeping installed software current reduces exposure to known vulnerabilities and can resolve problems in applications or system components.
A routine package update is not the same as replacing the operating system with a newer major release. The commands in this guide update packages within the installed system. They do not perform a major-release migration or reinstall the operating system.
Prepare before updating
Check the internet connection
The Raspberry Pi must be able to reach its configured software repositories. A repository is a source server that provides package metadata and software packages. Confirm that the Pi is connected to a reliable network before starting.
If the connection is unreliable, an update can stop partway through or fail to download files. See how to connect a Raspberry Pi to the internet if networking is not configured.
Save work and make a backup
Save open documents and stop important tasks before maintenance. For a significant update, especially on a system used for important projects, make a backup first. A backup gives you a way to recover personal files or configuration if a hardware or storage problem occurs during maintenance.
Check available storage
A filesystem is the storage structure that holds the operating system, applications, and user files. Package updates need free disk space for downloads, temporary unpacked files, and installation.
Open a terminal and run:
df -h
The -h option means human-readable output, such as megabytes or gigabytes rather than raw blocks. Find the entry mounted at /. This is usually the main root filesystem containing the operating system.
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p2 29G 12G 16G 43% /
In this example, the root filesystem has 16 GB available and is 43% used. Compare its Avail value with the additional space requested later by the package manager. If free space is low, remove unneeded files or expand the filesystem before upgrading. The guide to expanding the Raspbian filesystem covers one possible storage-related task.
Raspbian update workflow
Use this order:
- Verify the network connection and available root-filesystem space.
- Refresh the local package list.
- Review and install available upgrades.
- Check the result and restart if the output says a reboot is required.
Refreshing the package list should normally happen before the upgrade because the package manager needs current information about available package versions.
Refresh the package list
A package is a bundled unit of software and associated metadata managed by the operating system. The local package list is metadata describing packages and versions currently available from configured repositories.
Refresh that metadata with:
sudo apt-get update
APT contacts the configured repositories, downloads current package information, and stores it locally. This command does not install updated software. It only updates the information used to decide which package versions are available.
sudo runs a command with elevated administrative permissions. Package metadata is stored in protected system locations, so this operation normally requires administrative access. Enter your normal user password when prompted. The terminal will not display the password as you type. Use elevated privileges only for the intended package-management command, not for unrelated commands.
Upgrade installed packages
After the package list refresh completes successfully, run:
sudo apt-get upgrade
This installs newer available versions of packages that are already installed on the Raspberry Pi. It does not mean that every package in the repositories will be installed; it updates the installed packages for which newer versions are available.
The package manager normally shows a summary before making changes. The summary can include:
- Packages that will be upgraded, newly installed, or removed.
- The amount of data that must be downloaded.
- The additional disk space required after installation.
- A confirmation prompt, commonly asking whether to continue.
Review the summary. Continue only when the listed changes and storage requirements are acceptable. The package manager then downloads the packages and installs them. Do not switch off the Raspberry Pi while packages are being configured.
Some updates affect system components such as the kernel, firmware, or services. The output may request a reboot so that the updated components become active.
Raspbian update commands
Standard routine update example
- Open a terminal session. If needed, read how to use the terminal in Raspbian.
- Check storage with
df -hand locate the root filesystem mounted at/. - Refresh package information:
sudo apt-get update
- Read the output for errors.
- Start the package upgrade:
sudo apt-get upgrade
- Review the download size and additional disk-space requirement.
- Confirm the operation when the prompt appears.
- Wait for downloading, unpacking, and configuration to finish.
- Restart only if the output indicates that a reboot is needed.
Common update outcomes
No packages need updating
A successful upgrade can report that all installed packages are already current. This is a normal result. It means the package list was checked and no newer applicable package versions are available; no further package action is required.
After-update checks
Confirm that the command ended without errors. Messages about successful unpacking and configuration indicate progress, but an explicit error requires attention before assuming the upgrade completed.
If the output says a reboot is needed, save your work and restart the Raspberry Pi at a suitable time. A restart is especially appropriate after kernel, firmware, or service updates because the running system may otherwise continue using older components.
If storage was close to its limit, run the check again:
df -h
Compare the root filesystem's available space with the earlier result. Temporary package files may be removed automatically, but an upgrade can still leave less free space because newer software occupies more storage.
Troubleshooting update problems
Insufficient storage
If the upgrade cannot continue because storage is insufficient, run df -h and inspect the Avail value for the filesystem mounted at /. Remove unneeded files or packages, or expand the available storage. Run sudo apt-get upgrade again only after enough space is available.
Repositories cannot be contacted
If sudo apt-get update cannot contact a repository, check that the Raspberry Pi has a working network connection. Also confirm that its date and time are reasonable; an incorrect clock can interfere with secure connections. A repository or DNS service may be temporarily unavailable, so retry later if local connectivity and time are correct.
A confirmation prompt appears
The prompt is normally the package manager showing planned changes, download size, and disk-space impact. Review the summary and confirm only when the changes are expected and the storage requirement is acceptable. Do not close the terminal during installation.
A reboot is needed
Updated system components, including a kernel or services, may not be fully active until the system restarts. Save work, close applications, and reboot at a convenient time. Do not interrupt an upgrade before it has finished configuring packages.
Key points to remember
sudo apt-get updaterefreshes package metadata; it does not install updates.sudo apt-get upgradeinstalls newer versions of installed packages.- Run the metadata refresh before the upgrade so APT uses current repository information.
- Use
df -hto check human-readable filesystem usage, especially the root filesystem mounted at/. - Review download and disk-space summaries before accepting the upgrade.
- Restart when the update output requests it, particularly after kernel, firmware, or service updates.
For related package-management approaches, see Synaptic Package Manager and Raspbian repository. For more command-line practice, see useful terminal commands.