• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Add Apt Repository In Ubuntu / Debian

Written by Admin, Updated On May 23, 2020
apt, ubuntu
How to Add Apt Repository In Ubuntu

An APT repository is a local directory or network server which holds deb packages and metadata files, those are readable by the APT tools. This tutorial describes two methods to add Apt repository on your Ubuntu & Debian systems. The first method uses the add-apt-repository command to configure the repository and second is to manually add the repository.

Adding Repositories with add-apt-repository#

To add or remove a repository you need be logged in as root or user with sudo privileges.

Following is the basic syntax of the add-apt-repository command:

add-apt-repository [options] repository

There are two type of repository one is PPA repository that is in ppa:[user]/[ppa-name] format or a regular repository entry that can be added to the sources.list file.

To list all available options of the add-apt-repository command, in your terminal type man add-apt-repository.

Ubuntu 18.04 and newer the add-apt-repository will also update the package index if the repository public key is imported. In your system the package index is a set of records of available packages from repositories which are enable.

For instance, you want to install VS Code from their official repositories.

First import the repository public key using wget or curl:

wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -

Run the below command to add VS Code repository:

sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"

The repository will be added to sources.list file.

At this points you can install any of the packages from the newly enabled repository:

sudo apt install code

Adding PPA Repositories#

PPA, or Personal Package Archives is a service to upload Ubuntu source packages that are built and published with Launchpad as an apt repository. The add-apt-repository command creates a new file under the /etc/apt/sources.list.d/ directory when adding a PPA repository.

For example, to add LibreOffice you would run:

sudo add-apt-repository ppa:libreoffice/ppa

On prompt hit Enter to enable repository.

Once the PPA is added to your system you can install the repository packages:

sudo apt install libreoffice

It will install the package and all its dependencies.

Manually Adding Repositories#

You can add the apt repository line manually by editing the /etc/apt/sources.list file.

Open sources.list file with your text editor to add the repository:

sudo nano /etc/apt/sources.list

For example, to enable VS Code repository manually, add the following line at the end of file:

deb https://packages.microsoft.com/repos/vscode stable main

You can add this line to file without editing file using command. To append the repository line to the sources.list file run below command:

echo "deb https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list

You must update package index before installing the packages from newly added repositories:

sudo apt update

Now you can install packages from the newly added repository:

sudo apt install code

Conclusion#

We have shown you how to add apt repositories in Ubuntu.

Feel free to leave a comment if you have any questions.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install and Configure Redis on Ubuntu 20.04
Next Article   How to Find Files in Linux Using the Command Line

Related Posts

  • How to Install and Use PHP Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    January 31, 2023
  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023
  • How to Install Puppet Agent on Ubuntu 22.04

    How to Install Puppet Agent on Ubuntu 22.04

    January 22, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook