How to add Apt software source on Ubuntu

When using the Ubuntu Software Center or typing apt or apt-get from the terminal command line to install a package, the package is downloaded from one or more software sources. An APT software source is a network server or a local directory that contains deb packages and metafiles that can be read by APT tools.

Although the default Ubuntu software source has thousands of packages available, sometimes you still need to install software from third-party software sources.

In this guide, we will show you two ways to add apt software sources in Ubuntu and Debian systems. The first way is to use the add-apt-repository command, and the second way is to manually add software sources through a text editor.

1. Apt source file##

In Ubuntu and all other Debian series distributions, apt software sources are defined in the /etc/apt/sources.list file or in the /etc/apt/sources.list.d/ folder In a separate file.

The name of the software source files in the /etc/apt/sources.list.d/ directory must end with .list.

The general format in the /etc/apt/sources.list file is as follows:

deb http://repo.tld/ubuntu distro component...

The file format in the /etc/apt/sources.list.d/ directory is the same as the normal sources.list file format.

Most sources provide a key used to authorize the download of the software, which needs to be downloaded and imported.

To add or remove a software source, you need to log in as a root or sudo user.

Usually, instructions on how to enable a particular software source are included in the software's documentation.

2. Install add-apt-repository (add-apt-repository command not found )

add-apt-repository is a Python script that allows you to add an APT software source to /etc/apt/sources.list or a separate file in the /etc/apt/sources.list.d directory . This command can also be used to remove an existing software source.

If add-apt-repository is not available on your system, you may get an error message: "add-apt-repository command not found".

The add-apt-repository tool is included in the software-properties-common package. To install it, run the following command:

sudo apt update
sudo apt install software-properties-common

3. Use add-apt-repository to add software source##

The basic syntax of the add-apt-repository command is as follows:

add-apt-repository [options] repository

The repository can be a normal software source entry that can be added to the sources.list file, such as deb http://repo.tld/ubuntu distro component, or it can be a similar ppa:<user> /<ppa-name> PPA source in format.

To view all the options of the add-apt-repository command, enter man add-apt-repository in the terminal.

By default, on Ubuntu 18.04 or newer releases, if the public key is imported, add-apt-repository will also update the package index.

The package index is a database that records all available packages from software sources on your system.

For example, you want to install MongDB from their official software source.

First import the public key of the software source:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80--recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Use the following command to add MongoDB software source:

sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'

This software source will be added to the sources.list file.

You can now install any package from the newly enabled software source:

sudo apt install mongodb-org

If for any reason you want to remove a previously enabled software source, use the --remove option:

sudo add-apt-repository --remove 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'

Fourth, add PPA software source##

Personal Package Archive (PPA) is a service that allows users to upload Ubuntu source code packages built and made public through Launchpad.

When adding a PPA software source, the add-apt-repository command creates a new file in the /etc/apt/sources.list.d/ directory.

For example, to add the PPA of Jonathon F that provides FFmpeg, you need to run:

sudo add-apt-repository ppa:jonathonf/ffmpeg-4

When prompted, press Enter and the source will be enabled.

Press [ENTER] to continue or Ctrl-c to cancel adding it.

The public key of the PPA software source will be automatically downloaded and imported.

Once the PPA is added to your system, you can install the software source packages:

sudo apt install ffmpeg

The apt command will install the package and all its dependent packages.

Five, manually add software source##

If you want to have more control over how your software sources are organized, you can manually edit the file /etc/apt/sources.list and add the address of the apt software source in the file.

To demonstrate, we will enable the CouchDB software source and install the software. CouchDB is a free and open source fault-tolerant NoSQL database maintained by the Apache Free Software Foundation.

To add sources, open the sources.list file with your text editor.

sudo nano /etc/apt/sources.list

Add the software source to the last line of the file:

deb https://apache.bintray.com/couchdb-deb bionic main

If you don't use a text editor, you can also directly add the software source to the sources.list file by using the following command:

echo "deb https://apache.bintray.com/couchdb-deb $(lsb_release -cs) main"| sudo tee -a /etc/apt/sources.list

$(lsb_release -cs) will print out the code name of Ubuntu. For example, if you have Ubuntu 18.04, this command will print out bionic.

Another option is to create a new software source file in the /etc/apt/sources.list.d/ directory.

When manually configuring the software source, you still need to manually import the public source key into our system. To do this, use wget or curl:

curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | sudo apt-key add -

The above command will print out OK, which means that the GPG key has been imported by the urban management and the software package of this software source can be trusted.

When installing a package from a recently added software source, you must update the package index:

sudo apt update

Once the package index update is complete, you can install the package from the recently added software source:

sudo apt install couchdb

Six, summary##

We have shown how to add the apt software source in Ubuntu. The same instructions are also suitable for any Linux distribution based on Debian, including Kubuntu, Linux Mint and Elementary OS.

Recommended Posts

How to add Apt software source on Ubuntu
How to uninstall software on Ubuntu
How to add swap space on Ubuntu 20.04
How to replace apt-get source on Ubuntu 18.04
How to modify software source in Ubuntu 7.10
Explain how to add swap partition on Ubuntu 16.04
How to add logging module to Nginx on Ubuntu 16.04
How to add the gzip module to Nginx on Ubuntu 14.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to deploy Django on Ubuntu 14.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to secure Nginx on Ubuntu 14.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to add swap on CentOS 7
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04