Score:10

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

us flag

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?

Terrance avatar
id flag
Awesome question! I am not very good at aliases, but maybe setup an alias like `add-apt-repository -ny` but I am not that good at something like that.
mchid avatar
bo flag
@Terrance Because the command uses `sudo`, you'd have to add an alias for the `sudo` command: `alias sudo='sudo '` (with a blank space after sudo). Otherwise, `sudo` commands will not use your aliases.
Terrance avatar
id flag
@mchid Told you I was bad at it! :) That makes a lot of sense. Thanks! :)
muru avatar
us flag
As for Linux Mint, they use [their own antique copy of `add-apt-repository`](https://github.com/linuxmint/mintsources/blob/master/usr/bin/add-apt-repository).
Score:7
bo flag

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.

Liso avatar
sd flag
Clever workaround +1 !
Score:5
zw flag

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
#!/bin/bash
/usr/bin/add-apt-repository -n $@
EOF
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.

Score:3
my flag

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"])
        sys.exit(0)

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"])
        sys.exit(0)

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

Beginners

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"])
            sys.exit(0)   
    
  5. Remove the whole if code block mentioned above.

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

Test

Test

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
Someone avatar
my flag
For our smart minded downvoter: Consider explaining why you downvoted. This is exactly what they wanted. Feel free to edit or give suggestions. At least tell a reason for the downvote. I don't think that you downvoted just to lose 1 rep. Consider telling a reason, so that your loss of 1 rep does not get wasted.
ua flag
You're breaking a lot of things for upcoming updates. If you want to use a custom version, place it in `/usr/local/bin` which should come in `$PATH` before `/usr/bin` and is never used by official programs. So you won't break updates of `apt-add-repository` and reverting the change would just require deleting the file in `/usr/local/bin`. You are also suggesting a custom script that cannot easily be checked when other answers already suggest minimal wrapper scripts, which also solve the problem, are easy to understand and installed in a way that doesn't break future updates.
Someone avatar
my flag
@allo OK, I agree and fully accept your concern. However, it still seems to be at least a *fine* answer to me. So, I am not gonna delete it... However, feel free to edit and insert your concern about `/usr/local/bin` or post a new answer about the same. *You are also suggesting a custom script that cannot easily be checked* I should have clarified that the script only removed a line of code from it which removes the apt update thingy.
ua flag
It's not a bad answer per se. I only thought when you're asking for details why someone may downvote it, I'll try to point out a few issues that may cause it to have lower votes than the other answers. If you're suggesting to remove a few lines, try to explain this change and it can be really useful. When the upstream version may change in the future, your changes can possibly still be applied to the new version, but the changed copy will not contain the updates from upstream.
Someone avatar
my flag
@allo **Seems like I have fixed those issues in my latest edit.**
us flag
+1. However, this is way too complicated.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.