Managing Your Repositories Adding and Removing
Normally we use the apt command to install software onto our
Ubuntu system. The apt command is a part of the package management
software also named apt. Apt contains a whole suite of tools
that allows us to manage the packages and sources of our software, and to
install or remove software at the same time.
Let's walk through
adding and removing a repository using the add-apt-repository command.
Whilst you can install software through the use of package installers such as
dpkg, the benefits of apt means that whenever we update our system -- the
repository that contains the pieces of software that we add also
gets checked for updates. Ubuntu system
In this
example, we're going to add the text editor Sublime Text to our
Ubuntu machine as a repository as it is not a part of the default Ubuntu
repositories. When adding software, the integrity of what we download is
guaranteed by the use of what is called GPG (Gnu Privacy Guard) keys. These keys are essentially a safety check from the developers saying,
"here's our software". If the keys do not match up to what your system trusts
and what the developers used, then the software will not be downloaded.
So, to start, we need to add the GPG key for the developers of Sublime Text
3.
1. Let's download the GPG key and use apt-key to trust it:
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo
apt-key add -
2. Now that we have added this key to our trusted list, we can now add
Sublime Text 3's repository to our apt sources list. A good practice is to
have a separate file for every different community/3rd party repository that
we add.
2.1. Let's create a file named sublime-text.list in
/etc/apt/sources.list.d and enter the repository information like so:
┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$ sudo touch sublime-text.list 1 ⨯ ┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$ ls sublime-text.list vscode.list ┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$
2.2. And now use Nano or a text editor of your choice to add
& save the Sublime Text 3 repository into this newly created file:
┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$ sudo nano sublime-text.list ┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$
deb https://download.sublimetext.com/ apt/stable/
2.3. After we have added this entry, we need to update apt to
recognise this new entry -- this is done using the
apt update command
2.4. Once successfully updated, we can now proceed
to install the software that we have trusted and added to apt using
apt install sublime-text
┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$ sudo apt-get update Get:2 https://packages.microsoft.com/repos/vscode stable InRelease [3,959 B] h Get:3 https://download.sublimetext.com apt/stable/ InRelease [2,536 B] Get:1 http://kali.download/kali kali-rolling InRelease [30.6 kB] Get:4 https://packages.microsoft.com/repos/vscode stable/main amd64 Packages [305 kB] Get:5 http://kali.download/kali kali-rolling/main amd64 Packages [18.4 MB] Get:6 https://download.sublimetext.com apt/stable/ Packages [4,767 B] Get:7 http://kali.download/kali kali-rolling/main amd64 Contents (deb) [42.9 MB] Get:8 http://kali.download/kali kali-rolling/non-free amd64 Packages [213 kB] Get:9 http://kali.download/kali kali-rolling/non-free amd64 Contents (deb) [1,008 kB] Fetched 62.9 MB in 2min 15s (465 kB/s) Reading package lists... Done ┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$ ┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$ sudo apt-get install sublime-text Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: libcodec2-0.9 libdap27 libdapclient6v5 libepsilon1 libgdal28 libgeos-3.9.0 libnetcdf18 libodbc1 libodbccr2 libpoppler102 libpython3.9-dev libqhull8.0 libtbb2 liburing1 libx264-160 libyara4 odbcinst odbcinst1debian2 python3-llvmlite python3-parameterized python3.9-dev Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: sublime-text 0 upgraded, 1 newly installed, 0 to remove and 1535 not upgraded. Need to get 16.4 MB of archives. After this operation, 50.6 MB of additional disk space will be used. Get:1 https://download.sublimetext.com apt/stable/ sublime-text 4126 [16.4 MB] Fetched 16.4 MB in 21s (794 kB/s) Selecting previously unselected package sublime-text. (Reading database ... 295828 files and directories currently installed.) Preparing to unpack .../sublime-text_4126_amd64.deb ... Unpacking sublime-text (4126) ... Setting up sublime-text (4126) ... Processing triggers for kali-menu (2021.2.3) ... Processing triggers for desktop-file-utils (0.26-1) ... Processing triggers for hicolor-icon-theme (0.17-2) ... Processing triggers for mailcap (3.69) ... ┌──(hackerboy㉿KumarAtulJaiswal)-[/etc/apt/sources.list.d] └─$
Removing packages is as easy as reversing. This process is done by using
the add-apt-repository --remove ppa:PPA_Name/ppa
command or by manually deleting the file that we previously fulfilled. Once
removed, we can just use apt remove [software-name-here] i.e.
apt remove sublime-text