Linux Commands

Add-Apt-Repository Without User Input Prompt

In Linux OS, a number of packages are installed by default. However, these packages are never enough. You may need several packages over time. The Linux distribution Ubuntu uses apt for installing, updating, and removing the packages. The apt keeps the repositories in the single sources.list file under the /etc/apt/ directory. It also keeps the repositories in separate (.list) files under the /etc/apt/sources.list.d directory. To add a repository in Ubuntu, you need to either edit these files or you can use the add-apt-repository.

Usually, when you run the add-apt-repository command, it prompts for confirmation Press [ENTER] to continue or ctrl-c to cancel adding it. This guide covers using the add-apt-repository without a user prompt.

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

$ sudo add-apt-repository ppa:<ppa_name>

In the below example, we have added the ppa:ondrej/php to our system’s repository using the following command:

$ sudo add-apt-repository ppa:ondrej/php

You can see in the below screenshot that it has asked for confirmation.

If you do not want to see the user prompt while using the add-apt-repository command, you can bypass it by using the –yes or -y option after the add-apt-repository. Here is the syntax:

$ sudo add-apt-repository --yes ppa:<ppa_name>

The –yes or -y option assumes yes to all queries and does not prompt for user confirmation or approval. As you can see in the below screenshot, we have added the ppa:ondrej/php using the following command:

$ sudo add-apt-repository --yes ppa:ondrej/php

Now, it has not prompted for the user confirmation and added the ppa:ondrej/php repository.

That is all there is to it! I hope now you can add the apt repository in Ubuntu without a user prompt. However, remember that you will still be prompted for a password if you run the command as sudo.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.