There are several ways to install, remove and search software packages in Ubuntu, and the way you would install, remove and search software packages would depend on the package format.
Ubuntu ships with a Debian package as its standard package, but you might also encounter a package called snaps, you can learn about the differences between Debian and Snaps Packages.
The first rule of installing a certain software is to look at the software manufacturer's instruction or their website for how to install it on your distribution.
Most of the time you would be downloading a Debian package format via the apt install command, and in some cases, the software may have Snap available, the reason why snap is better is that you can install the latest version of the software without waiting for the next release of your distribution.
Anyways, let's start with Installing Debian packages...
Installing Software Packages Using APT
The apt install command is a tool among others in the APT or Advanced Package Tool for installing Debian packages. So, to install the software you use apt along with the install keyword and the package name.
For example, the following command will install the mysql-server package:
sudo apt install mysql-server
To install multiple packages at a time, you can separate the packages with space, e.g
sudo apt install <package1> <package2> <package3> <package4>
The above example will install four different packages.
One thing I want you to keep in mind is that, when you install a package with apt, the package might require other packages to function, this is called dependencies (rely on another package).
When you run the apt install command, it will check to ensure that the package is available in the repositories together with its dependencies.
For example, when I tried installing the mysql-server package, I got the following output:
user@server:~$ sudo apt install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7 Suggested packages: libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca The following NEW packages will be installed: libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7 0 upgraded, 21 newly installed, 0 to remove and 31 not upgraded. Need to get 19.7 MB of archives. After this operation, 156 MB of additional disk space will be used. Do you want to continue? [Y/n]
The output might look overwhelming but it's actually pretty easy...
I wanted to install only mysql-server package, but apt informs me that it also needs to install the packages under "
The following additional packages will be installed:"
This is telling us in order to make the package you are trying to install work properly, you also need those additional packages.
Also, you would see we also have suggested packages that are optional and are not required.
If you actually need them, you can install the suggested packages by appending the --install-suggest option to the apt install command. Installing the suggested package would install lots of unnecessary stuff you don't need, so, you can just install it individually or by looking at the ones you want, and install it using the multiple packages installation syntax I showed you above.
If you look towards the end of the output, you can see a prompt saying,
Do you want to continue? [Y/n]
The prompt is making sure everything is in place and you are sure of the packages you are installing before proceeding. To skip the prompt and instead assumes yes to the confirmation prompt, you can use the -y option along with the apt install command.
I see no reason as to why you should do this unless you are scripting your package installations where no prompt is needed.
Whenever you try installing a software package with the apt command, it searches its local database for the package you name, if it doesn't find it or the version you want is not available, you would see an error.
So, the best practice when installing packages is to first update the local database with new ones if made available, you do this using the following command:
sudo apt update
The apt update is used to download package information from all configured sources. You should note that it doesn't actually update any package, it only retrieves and scan the package index files from the source, so, if new ones are available, it would update them with the new information and if any packages have been removed, it would also clean up the info to the repo since that won't be of use any longer.
Removing Software Packages Using APT
You have probably seen how easy it is to install software using the apt install command, removing packages also follows the same syntax, just replace the install with remove:
sudo apt remove <package>
To remove multiple packages, separate the package names with space:
sudo apt remove <package1> <package2> <package3> <package4>
Keep in mind that, removing a software package removes all packaged data but leaves a small user configuration files behind, this is usually user configuration, so, if the removal was an accident, installing them will restore its function as before in that case.
If you would like to wipe out a package configuration doing removal (most software stores their configuration files in a subdirectory of /etc), you can use the --purge option, for example:
sudo apt remove --purge <package>
Searching Packages Using APT
While it is actually easier to install packages if you know their names, it might be a little difficult to narrow down if you are looking for a specific packages that has a certain feature. For example, if you want to install PHP modules for Apache or PostgresSQL, and you didn't know the name of the associated package.
There are couple of ways you can figure this out, the first way is to search for all php plugins. To search, you use the search keyword followed by the search term:
apt search php
This would return a long list of all php packages with a short description explaining what each of the packages does.
By default, apt search would search for all packages that has the search term, and if a package doesn't have that name, it would go ahead searching for descriptions of packages for the search term, which in turn returns a really long list.
To narrow down the list, you can use the --names-only option, which only searches for the package name, and not the description.
For example, try searching for php, and compare it to when you use the --names-only option:
apt search php apt search php --names-only
The second option would return a short list, and in some cases it might be the best thing to do.
You might be lost in the dust of packages returned, you can be more specific with your query, for example, I am searching for PHP modules for Apache, so, I would use the following command to narrow it down:
apt search php apache
hashcat/bionic 4.0.1-1 amd64 World's fastest and most advanced password recovery utility klone/bionic 2.1.0~rc1-1 all embedded web application development framework kopano-webapp-apache2/bionic 3.4.6+dfsg1-1 all WebApp for the Kopano Collaboration Platform - Apache2 libapache2-mod-auth-tkt/bionic 2.1.0+dfsg-1 amd64 lightweight single-sign-on authentication module for Apache libapache2-mod-authn-yubikey/bionic 1.0-1.2ubuntu1 amd64 Yubikey authentication provider for Apache libapache2-mod-php/bionic 1:7.2+60ubuntu1 all server-side, HTML-embedded scripting language (Apache 2 module) (default) libapache2-mod-php7.2/bionic-updates,bionic-security 7.2.24-0ubuntu0.18.04.3 amd64 server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-watchcat/bionic 1.1.2-1 amd64 Process monitoring Apache module libapache2-mod-xsendfile/bionic 0.12-2 amd64 Serve large static files efficiently from web applications libjs-jquery-jush/bionic 12-1 all jQuery Syntax Highlighter libwcat1/bionic 1.1-1.1 amd64 Process monitoring library libwcat1-dev/bionic 1.1-1.1 amd64 Process monitoring library nagios-plugins-contrib/bionic 21.20170222 amd64 Plugins for nagios compatible monitoring systems pear-channels/bionic 0~20141011-1 all PEAR channels for various projects phing/bionic 2.16.0-1 all PHP5 project build system based on Apache Ant php-cassandra/bionic 1.3.0-1build1 amd64 DataStax PHP Driver for Apache Cassandra php-cgi/bionic 1:7.2+60ubuntu1 all server-side, HTML-embedded scripting language (CGI binary) (default) php-letodms-lucene/bionic 1.1.1-2 all Document management system - Fulltext search php-solr/bionic 2.4.0-5build1 amd64 PHP extension for communicating with Apache Solr server php-stomp/bionic 2.0.1+1.0.9-4 amd64 Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP php-symfony-web-server-bundle/bionic-updates,bionic-security 3.4.6+dfsg-1ubuntu0.1 all provide commands for applications using the PHP built-in web server php-zend-code/bionic 3.2.0really3.1.0-1 all Zend Framework - Code component php7.2-cgi/bionic-updates,bionic-security 7.2.24-0ubuntu0.18.04.3 amd64 server-side, HTML-embedded scripting language (CGI binary) php7.2-fpm/bionic-updates,bionic-security 7.2.24-0ubuntu0.18.04.3 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) phpliteadmin/bionic-updates,bionic-security 126.96.36.199-1ubuntu0.1 all web-based SQLite database admin tool prayer/bionic 1.3.5-dfsg1-4build1 amd64 standalone IMAP-based webmail server prayer-accountd/bionic 1.3.5-dfsg1-4build1 amd64 account management daemon for Prayer prayer-templates-dev/bionic 1.3.5-dfsg1-4build1 amd64 tools for compiling Prayer templates prayer-templates-src/bionic 1.3.5-dfsg1-4build1 all templates for customizing Prayer Webmail watchcatd/bionic 1.2.1-3.1 amd64 Process monitoring daemon wwwconfig-common/bionic 0.3.0 all Debian web auto configuration yasat/bionic 848-1ubuntu1 all simple stupid audit tool yubikey-val/bionic 2.38-2 all One-Time Password (OTP) validation server for YubiKey tokens
Honestly, the list is actually a bit longer, using the --names-only option would give you the exact module you need, for example:
apt search php apache --names-only
libapache2-mod-php/bionic 1:7.2+60ubuntu1 all server-side, HTML-embedded scripting language (Apache 2 module) (default) libapache2-mod-php7.2/bionic-updates,bionic-security 7.2.24-0ubuntu0.18.04.3 amd64 server-side, HTML-embedded scripting language (Apache 2 module)
You can see how that command combo narrows down the list. You probably need the
libapache2-mod-php module, which can show more info on what it does using:
apt-cache show libapache2-mod-php
This would output more info about the package you are installing, let's take another example using the PostgreSQL module for PHP:
apt search php pgsql --names-only
PostgreSQL are usually shortened to pgsql in their package names!
Installing Software Packages Using Snap
Snap was released and pre-installed in Ubuntu 16.04 or later, if for some reason you are still below 16.04, you can install Snapd, which is the system service that enables you to interact with snaps.
Confirm the existence of Snap using:
The output should be /usr/bin/snap
or you can even just type snap
If the output is empty or you receive "The program 'snap' is currently not installed.", then snap is probably not installed, install it using the following command:
sudo apt update sudo apt install snapd
If you are just installing snapd for the first time, you would probably want to reboot your system before you start using the snap package.
The syntax of installing snap packages is similar to that of apt, for example, installing nextcloud snap package:
sudo snap install nextcloud
You can see it uses the same syntax as apt: snap install <package name>
One super useful feature of snapd is the ability to find a package using the find keyword, it queries the store for available packages in the stable channel. It would also show you a verified publisher with a green tick mark beside the publisher's name.
Let's try finding all MySQL packages or packages that require MySQL:
snap find mysql
Name Version Publisher Notes Summary mysql 5.7.17 ltangvald - Experimental MySQL Community snap nextcloud 17.0.3snap1 nextcloud✓ - Nextcloud Server - A safe home for all your data digikam 6.4.0 sergiusens - Photo Management Program datagrip 2019.3.3 jetbrains✓ classic IntelliJ-based IDE for databases and SQL smonitor 0.0.4beta-amd64 jes - Monitoring of server states (and other things) dbeaver-ce 188.8.131.52003021717 dbeaver-corp - Universal Database Tool gogs 0.1 vtuson - golang based git server and ui cdbc 0.2.0 fnordahl - C library providing simple and easy to use interfaces to the ODBC API squirrelsql 4.0.0 jibel - A Java SQL client for any JDBC compliant database query-exporter 2.1.0 ack - Export Prometheus metrics from SQL queries mysql-experimental 5.7.16 ltangvald - Experimental MySQL Community snap statup 0.79.91 hunterlong - Statup Server Monitoring with Status Page mysql-shell 8.0.17 ltangvald - MySQL Shell (part of MySQL Server) 8.0 mycli 1.8.1 khiemdoan - mycli is a command line interface for MySQL, MariaDB, and Percona. sync-and-dump-s3 0.9 scorching+shade - Sync aws s3 buckets and Upload dumps of mysql and mongodb restore-dump-s3 1.017 scorching+shade - Restore dumps of mysql and mongodb from aws s3 buckets trico 2.6.1 ngudbhav - Convert your Excel Spreadsheet to a table/collection in MYSQL/MongoDB vmcloud-nextcloud 1.0.0 victoriususm - Nextcloud 16.0.3 Optimized-Boosted dbeaverapp latest riednyko - Universal Database Tool
You see how it neatly returns the details of MySQL and the packages that require it, installing MySQL using the snap packages is still experimental as shown in the summary field above.
Also, you can see the green tick beside some of the packages, this is known as a verified publisher, only selected publishers are verified, so, it doesn't really mean much if there is no green tick, just take extra caution of the snap packages you install.
I should also mention that you can find tons of snap packages on the Snap Store
Removing Software Packages Using Snap
Removing snap packages is pretty straight forward, you simply use the remove option:
sudo snap remove nextcloud
The remove command removes the nextcloud snap package instance from the system.
Updating Software Packages Using Snap
Although snap would automatically update the packages once per day, if you are in a hurry, you can update a package using this syntax:
sudo snap refresh nextcloud
This would update the nextcloud snap package to the newest version if available.
To update all snap packages, use:
sudo snap refresh
To list packages that need updating without actually updating it, use:
snap refresh --list
To see which version are available for a certain package, type the following command:
snap info <package name>
To list all snap packages install on your system, use:
You can learn more about snap using the man page, see you later ;)