When I upgrade from 11.10 to 12.04, what's the best way to re-enable my PPAs and added repositories?
5 Answers
You need to add them all back/re-enabled them individually by uncommenting the lines in the files in the /etc/apt/sources.list.d/
directory.
Though upgrade time is a good time to reevaluate if you need the PPA in the first place if you were just using one to get a newer version of a package.

- 70,465

- 71,754
I wrote a bash script that removes the leading hash character from all files in sources.list.d
that were disabled during the upgrade.
The following code is for upgrading raring
sources to saucy
.
If you want to keep the suffix # disabled on upgrade to ...
, use
for f in /etc/apt/sources.list.d/*.list; do sudo sed -i 's/raring/saucy/g' $f; sudo sed -i 's/^# \(.*disabled on upgrade to.*\)/\1/g' $f;done
if you want to delete the suffix # disabled on upgrade to ...
, use
for f in /etc/apt/sources.list.d/*.list; do sudo sed -i 's/raring/saucy/g' $f; sudo sed -i 's/^# \(.*\) # disabled on upgrade to.*/\1/g' $f;done

- 316
- 3
- 6
Here's a python script that uses the Python APT API to find and enable such sources, while setting the release to the current release:
#! /usr/bin/python3
import aptsources.sourceslist as sl
import lsb_release
codename = lsb_release.get_distro_information()['CODENAME']
sources = sl.SourcesList()
for source in sources.list:
if source.comment.lower().find("disabled on upgrade") >= 0:
source.dist = codename
source.set_enabled(True)
print(source)
sources.save()
If you run it without sudo
, it won't be able to save changes, but it will show which sources would be enabled. Run with sudo
to save the changes.

- 197,895
- 55
- 485
- 740
To check and automatically update the source.list file, I created a script using curl
and codename
as follows.
#!/bin/bash
CODENAME="$(lsb_release -cs)"
for file in /etc/apt/sources.list.d/.list;
do
APT_URL="$(cat $file | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]' | sort | uniq)"
CURRENT_CODES="$(cat $file | rev | awk '{NF=2}1' | rev | awk '{print $1;}')"
LENGTH=${#APT_URL}
[[ ${APT_URL:LENGTH-1:1} != */ ]] && APT_URL="$APT_URL/"; :
NEW_APT_URL="${APT_URL}dists/${CODENAME}"
echo -n "$NEW_APT_URL"
STATUS=$(curl --head --location --write-out %{http_code} --silent --output /dev/null ${NEW_APT_URL})
if [[ $STATUS == 200 ]]; then
echo -en "\e[93m OK\033[0m"
for code in $CURRENT_CODES;
do
[[ $code != $CODENAME ]] && sudo sed -i "s/$code/$CODENAME/g" $file
done;
sudo sed -i 's/^# (.) # disabled on upgrade to./\1/g' $file
echo -e "\e[92m DONE\033[0m"
else
echo -e "\e[91m NOT FOUND\033[0m"
fi
done;
I have created a couple of scripts to both enable (re-enable) and disable PPAs, specially after an upgrade. Here they are:
PPA re-enable script
#! /bin/bash
# PPA re-enable script
# Use: ppa-reenable source.list
# to reenable a PPA without its source line
# Use: ppa-reenable src source.list
# to reenable a PPA with its source line
mod=1
file="$1"
if [ $1 == "src" ]; then mod=""; file="$2"; fi;
sudo sed -i "${mod}s/^# \(.*\) \(disabled on upgrade.*\)\?/\1/" "$file"
PPA disable script
#! /bin/bash
# PPA disable script
# Use: ppa-disable source.list
# to disable the PPA completely
# Use: ppa-disable src source.list
# to disable the source of the PPA only
file="${1}"
mod=""
# If its only needed to disable the source
if [ $1 = "src" ]; then mod="2"; file="${2}"; fi;
# If source line is disabled, don't comment it out
second="`sed -n 2p \"$file\"`"
second="${second:0:1}"
if ( [ $second == "#" ] && [ $mod != "2" ] ); then
mod="1"
fi
sudo sed -i "${mod}s/^/# /" "$file"
The sudo
is included so you can store this script in your home bin directory

- 197,895
- 55
- 485
- 740

- 5,971
sources.list.d
, and three alien ones insources.list
. Might this be something that Ubuntu takes care of automatically now? – Jeffrey Benjamin Brown Jul 02 '18 at 07:13sources.list
looks like, not much I can do. – muru Mar 19 '20 at 02:52