Ubuntu
Now Reading
Ubuntu: install, remove and manage packages

Ubuntu: install, remove and manage packages

by KieranOctober 7, 2015

No matter what you’re trying to achieve with your Ubuntu server, you’re likely to need to install something at some point.

The package management system is a derivative of that used in Debian Linux, whereby each package will contain all of the required files, data and instructions to deploy a new piece of software to your system.

The process to install and upgrade software will vary, depending on what you’re trying to install, however the commands available to you through the Ubuntu terminal are always the same and are outlined below.

DPKG

The first command is dpkg – this particular package can help you to install or remove software from your Ubuntu OS, however, it will not automatically download and install dependencies that your software many have (for example WordPress is dependent on MySQL).

This tool is therefore best used for those packages that are local to your machine.

CommandDescription
Dpkg -l This command lists all of the packages that are currently installed on your system.
Dpkg -l | grep apache2 To find out if a specific package is installed (without trawling through the entire list of installed packages), you'll want to use the grep function. This lets you search for a specific package name (in this case Apache)
Dpkg -L apache2 This particular function lists all of the files which are installed by a package.
Dpkg -S This command will tell you which package installed a particular file. For example dpkg -S /var/www/config.confThe output of this command will show you what package the file 'config.conf' belongs to.
Sudo dpkg -i filename.deb If you've downloaded a .deb package file to your system, you can use this command to install it.
Sudo dpkg -r packagename While it is not recommended that you use dpkg to remove packages (because it will not manage dependencies), you can do do it.

Apt-Get

The apt-get command works with Ubuntu’s Advanced Packaging Tool (APT) to help install and upgrade packages. You can add packages to your sources list (/etc/apt/sources.list).

CommandDescription
Sudo apt-get install packagename To install a package you simply use the command to the left. You can add multiple packages in a single command, just put a space between each of the package names.
Sudo apt-get remove packagename To remove a package, you just replace the word 'install' with 'remove'. You can add multiple packages in a single command, just put a space between each of the package names.
Sudo apt-get update A package index is a list of available packages, as defined in your /etc/apt/sources.list file.To update this, you can just type the command to the left.
Sudo apt-get upgrade After you've updated your package index (as above), you can update all of the out of date packages on your system.

Whenever you run an apt-get command, it makes a log of what you did. This can be found under /var/log/dpkg.log.

Aptitude

Install, remove and upgrade commands can be carried out with single-key commands through a menu driven interface (making life a little bit simpler for those of us that dislike the terminal).

To open aptitude just type ‘sudo aptitude’ into the terminal. You can exit aptitude by typing ‘q’ into the terminal.

TaskDescription
Install a package You can locate the package you want to install via the 'not installed packages' menu (by using keyboard arrows).When you hit enter, the package line will turn green (this means it has been marked for installation.If you press the 'g' button, you'll receive a summary of the actions you're about to take (i.e. the install). By pressing 'g' one more time, you'll kick off the install.
Remove a package You can locate the package you want to remove via the 'installed packages' menu (by using keyboard arrows).Select the package that you would like to remove and press the '-' key. This will result in the package being highlighted in pink.If you press the 'g' button, you'll receive a summary of the actions you're about to take (i.e. the uninstall). By pressing 'g' one more time, you'll kick off the removal.
Update package index As mentioned above, the package index houses a list of all the available packages.To update this list just press the 'u' key.
Upgrade packages Once you've updated the list, you'll want to upgrade the packages on your system. To do this, press the 'u' key on all of the packages with updates.If you press the 'g' button, you'll receive a summary of the actions you're about to take (i.e. the upgrades). By pressing 'g' one more time, you'll kick off the upgrade.

The package list uses the below key to describe the state of the packages:
KeyDescription
iInstalled
cNot installed (but config remains on system)
pPurged
vVirtual
bBroken
uUnzipped but not configured
cPart configured
hPart installed

Feel free to read our article in magazine format here

Image used under creative commons

This article was brought to you by Netshock. Netshock aim to provide technology guides and insight to our readers.

What's your reaction?
Love It
0%
Interested
0%
Meh...
0%
What?
0%
Hate It
0%
Sad
0%
About The Author
Kieran

My name is Kieran, I love to see how technology can drive business growth. I started the Netshock technology blog as a place to share my thoughts and experiences with a wider audience. I cover all sorts of topics, from marketing to development.