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:
In the below example, we have added the ppa:ondrej/php to our system’s repository using the following command:
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:
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:
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.