模板:U Lucid/Packages

来自Ubuntu中文
跳到导航跳到搜索

Package Installation and Updates

Apt and Package Basics

Most new users will use the Synaptic Package Manager to install packages. These instructions are for installing packages from the command-line Terminal. Terminal can be started:

Applications -> Accessories -> Terminal
  • Install packages:
sudo apt-get install packagename
  • Example:
sudo apt-get install mpd sbackup
  • Remove packages:
sudo apt-get remove packagename
  • To remove all dependencies:
sudo apt-get autoremove
  • Example:
sudo apt-get remove mpd sbackup
  • Search for packages:
apt-cache search <keywords>
  • Examples:
apt-cache search Music MP3
apt-cache search "Text Editor"
sudo apt-get update
  • Upgrade packages:
sudo apt-get upgrade
  • Upgrade the entire distribution (e.g. from Karmic to Lucid):
sudo apt-get dist-upgrade

Installing .deb packages

Debian (.deb) packages are the packages that are used in Ubuntu. You can install any .deb package in your system. .deb files can generally be installed from your file manager (Nautilus) merely by clicking on them, since file associations with the default installer is already set in Ubuntu. These instructions are for those who wish to install packages from the command-line terminal (Terminal).

  • Install a downloaded Debian (Ubuntu) package (.deb):
sudo dpkg -i packagename.deb
  • Remove a Debian (Ubuntu) package (.deb):
sudo dpkg -r packagename
  • Reconfigure/Repair an installed Debian (Ubuntu) package (.deb):
sudo dpkg-reconfigure packagename
*Example:
sudo dpkg-reconfigure mpd

Handling (Tar/GZip) and (Tar/Bzip2) archives

(Tar/GZip) archives end in ".tar.gz" and (Tar/Bzip2) archives end in ".tar.bz2". Bzip2 is the newer, more efficient compression method. These files can generally be automatically extracted by merely clicking on them from your file manager (Nautilus), since file associations with the appropriate archival utilities are set by default in Ubuntu. These instructions are for those who wish to use the command line Terminal.

  • To extract:
tar xvf packagename.tar.gz

Note: tar is an application which can extract files from an archive, decompressing if necessary.

-x means extract.
-v means verbose (list what it is extracting).
-f specifies the file to use.
  • Decompressing ".gz" files
gunzip file.gz
  • Decompressing ".bz2" files
bunzip2 file.bz2
Note: You can also decompress a package first by using the command gunzip (for .gz) or bunzip2 (for .bz2), leaving the .tar file. You would then use tar to extract it.
  • To create a .gz archive:
tar cvfz packagename.tar.gz folder
  • To create a .bz2 archive:
tar cvfj packagename.tar.bz2 folder

Installing a package from source

  • Make sure you have all the necessary development tools (i.e. libraries, compilers, headers):
sudo apt-get install build-essential linux-headers-$(uname -r)
Note: "uname -r" lists the current kernel you are using
  • Extract the archive that contains the source files:
tar xvf sourcefilesarchive.tar.gz
  • Build the package using the package's script (in this case the configure script), compile the package (make), and install the compiled package into your system (make install):
cd /path/to/extracted/sourcefiles
./configure
sudo make
sudo make install
Note: typing ./ before a filename in the current folder allows the Linux shell to try and execute the file as an application even if it is not in the path (the set of folders which it searches when you type a command name). If you get a "permission denied" error, the file is not marked as being executable. To fix this:
sudo chmod +x filename
Example: In the above instructions, configure is the shell script to build the package from source. To be sure the configure script is executable:
sudo chmod +x configure
Create a .deb package from source files

If your build from source is successful, you can make a Debian (Ubuntu) package (.deb) for future use:

  • Install package tools:
sudo apt-get install checkinstall
  • Rebuild package using "checkinstall":
cd /path/to/extracted/package
./configure
sudo make
sudo checkinstall
  • Keep the resulting ".deb" file for future use. It can later be installed using:
sudo dpkg -i packagename.deb

Note: These are basic instructions that may not always work. Some packages require additional dependencies and optional parameters to be specified in order to build them successfully. Also see these Ubuntu wiki instructions.

Aptitude

Aptitude is a terminal-based package manager that can be used instead of apt-get. Aptitude marks packages that are automatically installed and removes them when no packages depend on them. This makes it easy to remove applications completely. To use Aptitude, replace apt-get with aptitude in the command line. Example:

sudo aptitude install packagename
sudo aptitude remove packagename
sudo aptitude update
sudo aptitude upgrade

For an ncurses-based graphical user interface, type

sudo aptitude

For more information, see the aptitude documentation.

Synaptic Package Manager

While "apt-get" and "aptitude" are fast ways of installing programs/packages, you can also use the Synaptic Package Manager (System -> Administration -> Synaptic Manager), a GUI method for installing programs/packages. Most (but not all) programs/packages available with apt-get install will also be available from the Synaptic Package Manager. This is the preferred method for most desktop users. In this guide, when you see

sudo apt-get install package

you can simply search for package in Synaptic and install it that way.

  • System -> Administration -> Synaptic Package Manager
  • Search for the name of the program/package. You can also search for a word in its description.
  • Check the box "Mark for Installation"
  • Click the "Apply" button.
  • The selected program(s) will be automatically installed, along with its dependencies.

Add/Remove Programs

Not all packages available from apt-get, aptitude, and Synaptic Package Manager are available in Add/Remove Programs. However, it is the easiest interface for new users of Ubuntu and directs them to preferred packages.

  • Applications -> Add/Remove Programs
  • Search for the sort of program you want to add. Example: type MP3 to see a list of mp3 software.
  • Check the box "Mark for Installation"
  • Click the "Apply" button.
  • The selected program(s) will be automatically installed.

Manual Updates

  • Manually, from Terminal (command line interface):
sudo apt-get update
sudo apt-get upgrade
or
  • Use Synaptic Package Manager:
System -> Administration -> Synaptic Package Manager -> "Reload" then "Mark all upgrades"
If there are packages available for updating, you will be prompted whether to install them.

Automated Updates

  • Use Synaptic Package Manager:
  • System -> Administration -> Synaptic Manager -> Settings -> Preferences -> General -> Reloading Outdated Package Information -> Automatic