
September 11, 2026
12 min read
By Kokil Thapa | Last reviewed: September 2026
You need to install packages with apt on Ubuntu whenever you set up a web server, add PHP, or patch a production VPS. Apt is the default package manager on Ubuntu 22.04 and 24.04 LTS. It reads signed repositories, resolves dependencies, and installs software as root-managed `.deb` units. This guide walks through the commands I use daily on client servers—from a first nginx install to fixing the dreaded lock-file error. If you are new to the terminal, start with our essential Ubuntu terminal commands reference first.
sudo apt update, then sudo apt install package-name. Apt downloads the package and its dependencies from configured repositories, unpacks files to system paths, and registers the software for upgrades and removal.How do you install packages with apt on Ubuntu?
Apt (Advanced Package Tool) sits between you and Ubuntu's package index. You never download random `.deb` files from forums unless you have no other choice. The normal path is: refresh the index, find the exact package name, install, then confirm.
On a fresh Ubuntu Server install, log in as a user with sudo rights. Never run routine apt work as root without sudo—you want audit trails and fewer accidental system-wide edits.
Step 1: Refresh the package index
Before any install, sync your local index with remote repositories. Skipping this step is the most common reason apt reports "Unable to locate package".
sudo apt update That command does not upgrade installed software. It only downloads new package lists. For a deeper explanation of what happens under the hood, see apt update explained on Ubuntu.
Step 2: Install one or more packages
Use apt install with the exact binary or meta-package name from the repository.
sudo apt install nginx
sudo apt install php8.3-fpm php8.3-cli php8.3-mysql
sudo apt install git curl unzip Apt shows a summary: new packages, upgraded packages, disk space required. Press Y to confirm, or pass -y in scripts to auto-accept.
sudo apt install -y nginx Step 3: Verify the installation
Check that binaries exist and services are active.
nginx -v
systemctl status nginx
dpkg -l | grep nginx dpkg -l lists installed Debian packages. systemctl confirms systemd units—critical on any Ubuntu server setup.
- Run
sudo apt updateto refresh repository metadata. - Search with
apt search keywordor browse packages.ubuntu.com for the exact name. - Install with
sudo apt install package-name. - Verify with
dpkg -l, version flags, andsystemctl statuswhere applicable.
What is the difference between apt and apt-get on Ubuntu?
Both commands talk to the same backend: dpkg and the APT library. On modern Ubuntu, apt is the user-facing wrapper Ubuntu recommends. apt-get remains for scripts and older tutorials.
| Feature | apt | apt-get |
|---|---|---|
| Progress bar | Yes, coloured output | Plain text |
install | Yes | Yes |
upgrade | Yes (full-upgrade alias) | Yes (dist-upgrade) |
search | Built in | Use apt-cache search |
| Script stability | Interface not guaranteed frozen | Stable for automation |
| Default on Ubuntu 24.04 | Recommended for humans | Still installed, widely used in CI |
For interactive server work, I use apt. For Deployer hooks and GitLab CI jobs on production boxes, I often keep apt-get -y because behaviour has been predictable for years. After installs, run sudo apt upgrade on a schedule—see apt upgrade safely on Ubuntu for the full distinction between upgrade and dist-upgrade.
Official reference: the Ubuntu apt manual page documents subcommands and options for Noble (24.04).
How do you search and find packages before installing with apt?
Package names rarely match application marketing names. PHP-FPM is php8.3-fpm, not "php". MySQL server packages may be mysql-server-8.0 or MariaDB variants depending on the release.
Search from the terminal
apt search nginx
apt search php | grep fpm
apt show nginx apt show prints version, dependencies, installed size, and repository origin. That last field matters when you audit third-party PPAs.
List installed and available versions
apt list --installed | grep php
apt policy nginx apt policy reveals which repository version apt will pick. Pinning and extra repos belong in a dedicated Ubuntu repository management workflow—do not add random PPAs on production without reviewing signing keys.
Simulate before risky installs on live servers:
sudo apt install --simulate php8.3-fpm The dry run prints planned installs and removals without touching the system. Use it before adding Ondřej Surý's PHP PPA on a box that already runs distro PHP.
How do you install a full web stack with apt on Ubuntu?
Most of my Laravel and WordPress deployments on Ubuntu start with the same apt sequence. Versions shift by LTS release; always check apt search on the target server rather than copying stale package names from a blog.
Base tools
sudo apt update
sudo apt install -y curl git unzip software-properties-common Nginx and PHP
Ubuntu 24.04 ships PHP 8.3 in default repos. PHP 8.5 may require a PPA or newer release—verify with apt search php before scripting.
sudo apt install -y nginx
sudo apt install -y php8.3-fpm php8.3-cli php8.3-mysql php8.3-xml php8.3-mbstring php8.3-curl php8.3-zip Detailed walkthroughs: install Nginx on Ubuntu and install PHP on Ubuntu.
MySQL or MariaDB
sudo apt install -y mysql-server MySQL 8.4 LTS remains common on managed hosts. Ubuntu 24.04 may package MySQL 8.0 or 8.4 depending on archive updates—confirm with apt show mysql-server. See install MySQL on Ubuntu for secure mysql_secure_installation steps.
Redis, Node.js, and containers
sudo apt install -y redis-server
sudo apt install -y nodejs npm For Node.js 26 LTS, many teams prefer NodeSource or nvm over distro packages. Redis 8.x may not be in default Ubuntu repos—check version with redis-server --version after install. Container workflows often skip host Node entirely; see install Docker on Ubuntu instead.
Firewall after exposing services
sudo apt install -y ufw
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable Pair this with configure a firewall with UFW on Ubuntu and broader server hardening for Ubuntu web servers.
I have used this exact apt baseline on sister legal-tech sites that share a Deployer 7 pipeline—application code ships separately, but the stack always starts with apt. For Symfony-specific tuning after packages land, read Symfony deployment on Ubuntu VPS.
How do you remove, hold, and upgrade packages installed with apt?
Installing is half the lifecycle. You also need clean removal, controlled upgrades, and occasional version holds.
Remove packages
sudo apt remove nginx
sudo apt purge nginx
sudo apt autoremove remove uninstalls the package but may leave config files. purge deletes configs under /etc. autoremove clears orphaned dependencies pulled in earlier.
Upgrade installed packages
sudo apt update
sudo apt upgrade
sudo apt full-upgrade Schedule security updates on every public VPS. Unattended upgrades or weekly maintenance windows beat emergency Sunday patches. See Ubuntu security updates guide for automation patterns.
Hold a package at a fixed version
sudo apt-mark hold php8.3-fpm
apt-mark showhold Holds prevent accidental PHP bumps during a dist-upgrade. Release the hold before deliberate upgrades:
sudo apt-mark unhold php8.3-fpm How do you fix common apt install errors on Ubuntu?
Production servers throw repetitive apt errors. Most trace back to stale indexes, concurrent apt processes, or broken dependencies—not corrupt hardware.
Unable to locate package
Run sudo apt update. Confirm the package name with apt search. If the software needs a PPA or third-party repo, add the repo first—then update again. Jumping straight to add-apt-repository without understanding signing keys is a common security mistake on client VPS instances.
Could not get lock /var/lib/dpkg/lock
Another apt process—or an unattended upgrade—is running. Wait, or identify the holder:
ps aux | grep -E 'apt|dpkg'
sudo lsof /var/lib/dpkg/lock-frontend Never delete lock files while dpkg is active. If a process died mid-run:
sudo dpkg --configure -a
sudo apt install -f dpkg --configure -a finishes interrupted configuration. apt install -f fixes broken dependency states.
Unmet dependencies or broken packages
sudo apt --fix-broken install
sudo dpkg --remove --force-remove-reinstreq problematic-package Use force removal only when you understand what pulled the package in. Check logs:
less /var/log/dpkg.log
less /var/log/apt/term.log Hash sum mismatch or 404 from mirror
Switch mirrors or retry after sudo apt update. On Nepal-hosted VPS boxes, I sometimes see transient mirror lag during upstream sync windows. Waiting thirty minutes or changing to the main archive often clears it.
Wrong file permissions after manual edits under /var/lib/apt also break apt. Restore ownership if you touched those paths during a rushed debug session:
sudo chown -R root:root /var/lib/apt/lists
sudo chmod -R 644 /var/lib/apt/lists/*
sudo chown root:root /var/lib/apt/lists/lock
sudo chown root:root /var/lib/dpkg/lock File permission fundamentals live in Ubuntu file permissions explained.
Install a local .deb file
Prefer repositories. When a vendor ships a `.deb` directly:
sudo apt install ./teamviewer_amd64.deb Using apt install ./file.deb—not raw dpkg -i—lets apt pull missing dependencies from repos automatically.
What apt practices matter on production Ubuntu servers?
Treat apt changes like code deploys: predictable, logged, and reversible where possible.
- Always run
apt updateimmediately beforeapt installorupgrade. - Use
--simulatebefore installing meta-packages that might remove existing tools. - Document non-default repos in your runbook—future you will forget why a PPA exists.
- Snapshot the VPS or verify backups before
full-upgradeon a live database server. - Reload PHP-FPM and web servers after library upgrades:
sudo systemctl reload php8.3-fpm nginx. - Keep kernel and microcode upgrades on a separate maintenance window—they often need reboots.
On budget Nepal VPS plans (Rs 800–2,500/month, roughly USD 6–19), a broken apt state can take a site offline longer than application bugs. That is why many clients route server work through Linux system administration in Nepal or ongoing support and maintenance instead of experimenting on production.
Application-layer work—Laravel queues, WooCommerce checkout, API integrations—still depends on this foundation. Browse the Adventure Third Pole Trek portfolio case for an example where Ubuntu packages, PHP-FPM, and deployment automation sit underneath a Livewire booking system.
When you need quick JSON config checks while editing nginx or app env files, the free JSON formatter tool on this site saves a round trip to another tab. For broader context on who maintains these guides, see about me or the main services overview.
Performance tuning after packages are installed belongs in a separate pass—optimize Ubuntu server performance covers sysctl, PHP-FPM pools, and MySQL buffers once apt work is done.
Key Takeaways
- Run
sudo apt updatebefore every install so the index matches live repositories. - Install with
sudo apt install package-name; verify usingdpkg -landsystemctl status. - Use
apt searchandapt showto confirm exact package names before scripting. - Fix lock errors by waiting or running
dpkg --configure -a, not by deleting locks blindly. - Remove cleanly with
apt purgeplusautoremovewhen uninstalling services. - Simulate risky installs with
apt install --simulateon production hosts.
People Also Ask
Do you need sudo to install packages with apt on Ubuntu?
Yes. Installing system packages writes to /usr, /etc, and the dpkg database—all root-owned. Standard users run sudo apt install. Ubuntu disables direct root login by default, which is the safer pattern for SSH-managed servers.
What is the difference between apt install and apt upgrade?
apt install package adds new software. apt upgrade updates already-installed packages to newer versions within the same Ubuntu release. Neither installs a new distribution version—that requires do-release-upgrade.
Can you install multiple packages in one apt command?
Yes. Chain names in one line: sudo apt install nginx php8.3-fpm mysql-server. Apt resolves the combined dependency tree once, which is faster and easier to log than three separate installs.
How do you list all packages installed with apt on Ubuntu?
Run apt list --installed or dpkg-query -l. Filter with grep when hunting a specific stack component. Export the list before major upgrades so you can diff if something disappears.
Build on a clean apt foundation
Every production site I maintain on Ubuntu still starts the same way: update the index, install packages with apt on Ubuntu deliberately, verify services, then harden and deploy application code. Apt is boring technology—and that is exactly why it belongs at the base of your stack. When you want the full server built, secured, and handed over with runbooks, contact us or explore web development services in Nepal for end-to-end delivery.
Frequently Asked Questions
0 Comments
Leave a comment
Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

