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?
For a specific user, you can add an alias for
add-apt-repository
.Add the following lines to the end of your
~/.bashrc
file:After you save the changes, don't forget to source your
~/.bashrc
file:Keep in mind that the first line is necessary to use aliases with
sudo
. If you have aliases you want to exclude fromsudo
use, this might not be the best method.For system-wide method I would create local wrapper script placed into
/usr/local/bin
as followsand do not forget about the
apt-add-repository
synonym command - runThen use any of these commands with
-n
option auto-added.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: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:
NOTE: Edit this file with a terminal-text-editor like
nano
instead of GUI editors likegedit
.Beginners
Open a terminal using Ctrl + Alt + T
First, install nano:
Edit the file:
Press the down arrow key repeatedly,unless you reached the end of the file.
You'll find an
if
statement which looks exactly like this:Remove the whole
if
code block mentioned above.Press Ctrl + X and then select Y and press ENTER.
Test
Restore the file
Messed up?
No worry! If we run
dpkg -S
on the file, we can see:So just run: