CommandLine - Community Help Wiki

  • 4,000
  • Tác giả: admin
  • Ngày đăng:
  • Lượt xem: 4
  • Tình trạng: Còn hàng

IconsPage/terminal.png This page describes how to tát manage software repositories from the command line. (GUI tools are also available: Managing Repositories in Ubuntu or Kubuntu).

IconsPage/important.png If you are using a minimal install or server install you will need to tát be familiar with a terminal based text editor lượt thích nano. If you are using a GUI install you can use Nano or GEdit.

The Basics

Ubuntu uses apt for package management. Apt stores a list of repositories or software channels in the tệp tin

/etc/apt/sources.list

and in any tệp tin with the suffix .list under the directory

/etc/apt/sources.list.d/

See man sources.list for more about this storage mechanism.

By editing these files from the command line, we can add, remove, or temporarily disable software repositories.

  • IconsPage/note.png Note: It's always a good idea to tát backup a configuration tệp tin lượt thích sources.list before you edit it. To tự sánh, issue the following command:

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup


Typically, the beginning of the tệp tin /etc/apt/sources.list looks lượt thích this:

# sources.list
#deb cdrom:[Ubuntu 13.10 _Saucy Salamander_ - Release i386 (20131016.1)]/ saucy main restricted

# See http:///community/UpgradeNotes for how to tát upgrade to
# newer versions of the distribution.
deb http://ch.archive.ubuntu.com/ubuntu/ saucy main restricted
deb-src http://ch.archive.ubuntu.com/ubuntu/ saucy main restricted
#...

Explanation of the Repository Format

  • All the lines beginning with one or two hashes (#) are comments, for information only.
  • The lines without hashes are apt repository lines. Here's what they say:

    • deb: These repositories contain binaries or precompiled packages. These repositories are required for most users.

    • deb-src: These repositories contain the source code of the packages. Useful for developers.

    • http://archive.ubuntu.com/ubuntu: The URI (Uniform Resource Identifier), in this case a location on the mạng internet. See the official mirror list or the self-maintained mirror list to tát find other mirrors.

    • saucy is the release name or version of your distribution.

    • mainrestricted are the section names or components. There can be several section names, separated by spaces.

Other Versions

  • IconsPage/note.png For other Ubuntu releases you would replace the 'saucy' with the current version you have installed ('precise', 'quantal', 'raring', 'saucy', 'trusty', ...) Type lsb_release -sc to tát find out your release.

Adding Repositories

Adding the Universe and Multiverse Repositories

Additional software repositories such as Universe and Multiverse can be enabled by uncommenting the corresponding apt lines (i.e. delete the '#' at the beginning of the line). For Universe, uncomment those lines:

  • deb http://us.archive.ubuntu.com/ubuntu/ saucy universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ saucy universe
    deb http://us.archive.ubuntu.com/ubuntu/ saucy-updates universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ saucy-updates universe

There are four similar lines for 'multiverse'.

OR you may use the add-apt-repository command. If your release is 'saucy':

  • sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ saucy universe multiverse"
    sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ saucy-updates universe multiverse"

IconsPage/note.png Depending on your location, you should replace 'us.' by another country code, referring to tát a mirror server in your region. Check sources.list to tát see what is used!

Type lsb_release -sc to tát find out your release. You may repeat the commands with "deb-src" instead of "deb" in order to tát install the source files.

Don't forget to tát retrieve the updated package lists:

  • sudo apt-get update

Adding Partner Repositories

You can add the partner repositories by uncommenting the following lines in your /etc/apt/sources.list file:

  • deb http://archive.canonical.com/ubuntu saucy partner
    deb-src http://archive.canonical.com/ubuntu saucy partner

Then update as before:

  • sudo apt-get update

    IconsPage/important.png Be aware that the software contained within this repository is NOT open source.

Adding Other Repositories

There are some reasons for which you might want to tát add non-Ubuntu repositories to tát your list of software sources. Caution: To avoid trouble with your sytem, only add repositories that are trustworthy and that are known to tát work on Ubuntu systems!


  • You can add custom software repositories by adding the apt repository line of your software source to tát the kết thúc of the sources.list tệp tin. It should look something lượt thích this:

    deb http://mirror3.ubuntulinux.nl/ hardy-seveas freenx
  • Don't forget to tát make apt aware of your changes:
    sudo apt-get update

Adding Launchpad PPA Repositories

Adding Launchpad PPA (Personal Package Archive) is possible conveniently via the command: add-apt-repository. This command is similar to tát "addrepo" on Debian.

  • The command updates your sources.list tệp tin or adds/edits files under sources.list.d/. Type man add-apt-repository for detailed help.

  • If a public key is required and available it is automatically downloaded and registered.
  • Should be installed by mặc định. On older or minimal Ubuntu releases, you may have to tát install software-properties-common and/or python-software-properties first (sudo apt-get install python-software-properties)

    sudo add-apt-repository ppa:

    Example: sudo add-apt-repository ppa:nhandler/ppa

Enabling Repositories with a (non-interactive) Script

IconsPage/note.png This section seemed obsolete due to tát the add-apt-repository command, thus it has been removed.

Suggestions và Recommendations

  • It is always a good idea to tát back up configuration files lượt thích /etc/apt/sources.list before you begin editing. You can then revert your changes if needed.

  • If you decide to tát add other repositories to tát sources.list, make sure that the repository is meant to tát work (and known to tát work) with Ubuntu. Repositories that are not designed to tát work with your version of Ubuntu can introduce inconsistencies in your system and might force you to tát re-install. Also, make sure that you really need to tát add external repositories as the software package(s) you are looking for may already have been introduced into the official repositories!

  • Please keep in mind that it may not be legal (typically because of export restrictions) to tát enable some non-Ubuntu software repositories in some countries.

  • You may be asked enter a security key when adding a non-Ubuntu repository to tát your sources. See Managing Authentication Keys for instructions.

  • Remember to tát retrieve updated package lists by issuing a sudo apt-get update when you're done editing sources.list.

Further Reading

  • The Debian Apt User Manual

  • Apt-get

  • Software Management

  • Secure Apt on the Debian Wiki


CategoryCommandLine CategoryPackageManagement