Add Ubuntus default repositories from shell

Often you see instructions for this step which refer either to use the graphical tools like Synaptic or Software Sources, or to edit the /etc/apt/sources.list by hand (bad habbit).

Why not use Software Sources command line parameters to do this automatically?

Add default repository


The tool that's accessed from Ubuntus administration menu is called software-sources-gtk. It can be given the name of the repository that should be enabled on the command line.

Example for installing partimage from universe repository


sudo software-sources-gtk -e universe
sudo apt-get update
sudo apt-get install partimage


That way, you can enable any of the four repositories main, universe, restricted, and multiverse.

Update for Ubuntu Hardy


The command changed lately from software-sources-gtk to software-properties-gtk.

Add third party repositories


Again, you shouldn't edit the /etc/apt/sources.list configuration directly, but instead you simply create a new file xyz.list in the /etc/apt/sources.list.d folder.

Example of adding repository for KeepassX


sudo add-apt-repository ppa:keepassx

# For Hardy
sudo echo "deb http://ppa.launchpad.net/keepassx/ubuntu/ hardy main # KeepassX" > /etc/apt/sources.list.d/keepassx.list
sudo apt-get update

That way, it's much simpler to automate tasks like adding and removing third party repositories from shell scripts and keep your /etc/apt/sources.list file clean.

Y-PPA-Manager

With Natty there comes another repository manager, more graphically, but can be used from shell too. Read more about it in this post.

No comments:

Post a Comment