How to use the apt command to install packages
The Raspberry Pi's Operating System, Pi OS (previously know as Raspbian) is based on Debian linux and has a repository of available software accessible through the apt command.
The apt command is used within a terminal window to install software on the Raspberry Pi. Apt is also used to update and remove the Pi OS software which is also know as packages.
You will often find references to the apt-get command on guides and advice online. apt-get was previously used but most functions are now available in apt. So for this guide I will use the apt command.
I will go through the steps to install and remove a package using the apt command on Pi OS.
This guide will also work if your are using any Debian based operating system on any computer.
To load the terminal either select the terminal icon on the menu bar of the Desktop or from the Accessories menu.
For this example we will install the game Frozen Bubble2. A colour based Puzzle game similar to the arcade game Bust-a-Moves or Puzzles Bubble
The apt command needs to know what the latest available packages are. As there are updates most days this should be done before you install any software each day. To update the package list use the command sudo apt update
.
The sudo command give you temporary permissions to use the apt command. Without this you would not have permission to make any changes.
Various information will be displayed while it updates. Once it has finished type in sudo apt install frozen-bubble
Often at this stage you will get some information about what is going to be installed and do you want to continue Y/N
If this happens enter Y. In this case I was not asked.
That's it, Frozen Bubble is installed and now in the main menu under Games
Now you can start playing
When a packages is installed other software packages may get installed that you have not selected as they are required for your package to work.
Sometimes though your program will not work when you run it. If you run the program in terminal you will get a message saying why the program did not run. You can then look into what additional packages you need to install to get the program working or search the internet for further help.
How to Un-install a package
To un-install Frozen-bubble use the remove command.
sudo apt remove frozen-bubble
Search for Packages
If you are not sure what the name of the program you want is you can do a search which will list all the packages with the word you enter. You can then see what the correct name is to install the package.
So I want to install that game again, you know colour bubble or whatever it is called. I know bubble is in the name so I enter the command
sudo apt search bubble
Note: if you haven't done an update recently then use sudo apt update
before you search.
You will see a list of all packages with matching results including Frozen-Bubble
Clean up
If you install and remove lots of packages then it is a good idea to do an occasional clean up to make sure no unneeded files and packages are left behind.
Use sudo apt autoremove
Check what Packages are installed
To get a list of the software packages that are already installed on Pi OS enter the command dpkg --get-selections
If you just want to find out if a package is installed already use dpkg --get-selections | grep packagename
if you are unsure of the name you can enter any text after grep, all results containg that word will be shown.