How to permanetly disable automatic package cache update after adding a PPA?


Answer: 1

17 hours ago

In recent releases of Ubuntu, adding a PPA automatically updates the package cache immediately.

Sometimes, I need to add several PPAs (e.g. after a new installation), and would like to manually run apt update in one go, after adding all the PPAs.

How to do that?

I found this question, which suggests using add-apt-repository -n ppa:user/repo.

How to change the default behavior so that the package cache will not be updated even when the -n flag is not supplied?

For example, in Linux Mint, the package cache is never automatically updated after adding a PPA. How to make that the default behavior in Ubuntu?

Answer: 2

30 hours ago

For a specific user, you can add an alias for add-apt-repository.

Add the following lines to the end of your ~/.bashrc file:

alias sudo='sudo '
alias add-apt-repository='add-apt-repository -n'
alias apt-add-repository='add-apt-repository -n'

After you save the changes, don't forget to source your ~/.bashrc file:

. ~/.bashrc

Keep in mind that the first line is necessary to use aliases with sudo. If you have aliases you want to exclude from sudo use, this might not be the best method.

Answer: 3

21 hours ago

For system-wide method I would create local wrapper script placed into /usr/local/bin as follows

cat <<\EOF | sudo tee /usr/local/bin/add-apt-repository
/usr/bin/add-apt-repository -n [email protected]
sudo chmod +x /usr/local/bin/add-apt-repository

and do not forget about the apt-add-repository synonym command - run

sudo ln -s /usr/local/bin/add-apt-repository /usr/local/bin/apt-add-repository

Then use any of these commands with -n option auto-added.

Added by: Rudy Cronin

Answer: 4

17 hours ago

Advanced Users

You can modify the source code to remove the apt update command.

Here is the code block you need to remove from the /usr/bin/add-apt-repository file:

        if update and not options.remove:
            os.execvp("apt-get", ["apt-get", "update"])

This will remove the update command.

NOTE: This piece of code comes two times in the file, you have to remove the LAST one. This piece of code in most files would be somewhere near line 198.

You can open the file using a text editor such as nano and remove this piece of code.

You can also modify the code a bit, something like:

        if update and not options.remove:
            os.execvp("apt-get", ["apt-get", "moo"])

NOTE: Edit this file with a terminal-text-editor like nano instead of GUI editors like gedit.


Open a terminal using Ctrl + Alt + T

  1. First, install nano:

    sudo apt update
    sudo apt install nano
  2. Edit the file:

    sudo nano /usr/bin/add-apt-repository
  3. Press the down arrow key repeatedly,unless you reached the end of the file.

  4. You'll find an if statement which looks exactly like this:

            if update and not options.remove:
                os.execvp("apt-get", ["apt-get", "update"])
  5. Remove the whole if code block mentioned above.

  6. Press Ctrl + X and then select Y and press ENTER.



Restore the file

Messed up?

No worry! If we run dpkg -S on the file, we can see:

$ dpkg -S /usr/bin/add-apt-repository 
software-properties-common: /usr/bin/add-apt-repository

So just run:

sudo apt update
sudo cp -r /usr/bin/add-apt-repository /tmp
sudo rm -rf /usr/bin/add-apt-repository
sudo apt install software-properties-common --reinstall

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9