“UbuntuHelp:AptGet/Howto”的版本间的差异
来自Ubuntu中文
小 |
小 |
||
第56行: | 第56行: | ||
du -sh /var/cache/apt/archives</nowiki></pre> will tell you how much space cached packages are consuming. | du -sh /var/cache/apt/archives</nowiki></pre> will tell you how much space cached packages are consuming. | ||
*<pre><nowiki> | *<pre><nowiki> | ||
− | dpkg-reconfigure <package_name></nowiki></pre> Reconfigure the named package. With many packages, | + | dpkg-reconfigure <package_name></nowiki></pre> Reconfigure the named package. With many packages, you’ll be prompted with some configuration questions you may not have known were there. |
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D For example: <pre><nowiki> | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D For example: <pre><nowiki> | ||
dpkg-reconfigure fontconfig-config</nowiki></pre> will present you with a "wizard" on configuring fonts in Ubuntu. | dpkg-reconfigure fontconfig-config</nowiki></pre> will present you with a "wizard" on configuring fonts in Ubuntu. |
2008年10月19日 (日) 09:56的版本
- title Using APT
{i} This article applies to all supported versions of Ubuntu
目录
Package management with APT
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconApt.png%7D%7D Package management via apt-get runs hand-in-hand with the /etc/apt/sources.list file. For information on editing or updating your sources list see SourcesList.
Introduction to APT
"In the beginning there was the .tar.gz. Users had to compile each program that they wanted to use on their GNU/Linux systems. When Debian was created, it was deemed necessary that the system include a method of managing the packages installed on the machine. The name dpkg was given to this system. Thus the famous 'package' first came into being on GNU/Linux, a while before Red Hat decided to create their own 'rpm' system. A new dilemma quickly took hold of the minds of the makers of GNU/Linux. They needed a rapid, practical, and efficient way to install packages that would manage dependencies automatically and take care of their configuration files while upgrading. Here again, Debian led the way and gave birth to APT, the Advanced Packaging Tool, which has since been ported by Conectiva for use with rpm and has been adopted by some other distributions." -- From Debian APT HOWTO
Commands
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png%7D%7D All of these commands must be run as root or with superuser privileges, see sudo for more information. Replace with the name of the package you are attempting to install. |
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D
sudo apt-get install ubuntu-desktop
Installation commands
man aptitude
for more information.
- APT and aptitude will accept multiple package names as a space delimited list. For example:
apt-get install <package1_name> <package2_name> <package3_name>
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconNote.png%7D%7D Use the -s flag to simulate an action."sudo apt-get -s install " will simulate installing the package showing you what packages will be installed and configured. |
auto-apt
- Auto-apt keeps databases which need to be kept up-to-date in order for it to be effective. This is achieved by calling the commands auto-apt update, auto-apt updatedb and auto-apt update-local.
- Usage example<
>
# auto-apt run ./configureIt will then ask to install the needed packages and call apt-get automatically. If you're running X, a graphical interface will replace the default text interface.
Maintenance commands
This is not the recommended way to perform a distribution upgrade. See upgrading for more information.
- The package cache is in /var/cache/apt/archives . The command
dpkg-reconfigure fontconfig-configwill present you with a "wizard" on configuring fonts in Ubuntu.
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png%7D%7D This command may have the unintended side effect of preventing upgrades to packages that depend on updated versions of the pinned package. apt-get dist-upgrade will override this, but will warn you first. If you want to use this command with sudo, you need to use echo "<package_name> hold" | sudo dpkg --set-selections not sudo echo "<package_name> hold" | dpkg --set-selections .
|
Removal commands
- + operator
apt-get purge remove <package1> <package2>+.
Search commands
apt-cache search
, but also shows whether a package is installed on your system by marking it with ii (installed) and un (not installed).
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png%7D%7D In order to use this command, the package dlocate must be installed on your system. |
dlocate
, but does not require the installation of any additional packages. It is slower than dlocate
but has the advantage of being installed by default on all Debian and Ubuntu systems.
- apt-file needs to be updated regularly like apt-get. Use the command:
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png%7D%7D In order to use this command, the package apt-file must be installed on your system. |
- A general note on searching: If searching for a generates a list that is too long, you can filter your results by piping them through the command
grep
. Examples:
For more information on apt-get, apt-cache and dpkg consult their manual pages by using the man
command. These manuals will provide a wider scope of information in addition to all of the options that you can use with each program.
man apt-get.
Typical usage example
I want to feel the wind in my hair, I want the adrenaline of speed. So lets install a racing game. But what racing games are available?
apt-cache search racing game
It gives me a lot of answers. I see a game named "torcs". Lets get some more information on this game.
apt-cache show torcs
Hmmm... it seems interesting. But is this game not already installed on my computer? And what is the available version? Is it from Universe or main?
apt-cache policy torcs
Ok, so now, let's install it!
apt-get install torcs
What is the command I must type in the console to launch this game? In this example, it's straightforward ("torcs"), but that's not always the case. One way of finding the name of the binary is to look at what files the package has installed in "/usr/bin". For games, the binary will be in "/usr/games". For administrative programs, it's in "/usr/sbin".
dpkg -L torcs | grep /usr/games/
The first part of the command display all files installed by the package "torcs" (try it). With the second part, we ask to only display lines containing "/usr/games/". Hmmm, that game is cool. Maybe there are some extra tracks?
apt-cache search torcs
But I'm running out of space. I will delete the apt cache!
apt-get clean
Oh no, my mother asked me to remove all games from this computer. But I want to keep the configuration files so I can simply re-install it later.
apt-get remove torcs
If I want to also remove config files :
apt-get purge torcs
Setting up apt-get to use a http-proxy
These are three methods of using apt-get with a http-proxy.
Temporary proxy session
This is a temporary method that you can manually use each time you want to use apt-get through a http-proxy. This method is useful if you only want to temporarily use a http-proxy. Enter this line in the terminal prior to using apt-get (substitute your details for yourproxyaddress and proxyport).
export http_proxy=http://yourproxyaddress:proxyport
APT configuration file method
This method uses the apt.conf file which is found in your /etc/apt/ directory. This method is useful if you only want apt-get (and not other applications) to use a http-proxy permanently.
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png%7D%7D On some installations there will be no apt-conf file set up. This procedure will either edit an existing apt-conf file or create a new apt-conf file. |
gksudo gedit /etc/apt/apt.conf
Add this line to your /etc/apt/apt.conf file (substitute your details for yourproxyaddress and proxyport).
Acquire::http::Proxy "http://yourproxyaddress:proxyport";
Save the apt.conf file.
BASH rc method
This method adds a two lines to your .bashrc file in your $HOME directory. This method is useful if you would like apt-get and other applications for instance wget, to use a http-proxy.
gedit ~/.bashrc
Add these lines to the bottom of your ~/.bashrc file (substitute your details for yourproxyaddress and proxyport)
http_proxy=http://yourproxyaddress:proxyport export http_proxy
Save the file. Close your terminal window and then open another terminal window or source the ~/.bashrc file:
source ~/.bashrc
Test your proxy with sudo apt-get update and whatever networking tool you desire. You can use firestarter or conky to see active connections. If you make a mistake and go back to edit the file again, you can close the terminal and reopen it or you can source ~/.bashrc as shown above.
source ~/.bashrc
How to login a proxy user
If you need to login to the Proxy server this can be achieved in most cases by using the following layout in specifying the proxy address in http-proxy. (substitute your details for username, password, yourproxyaddress and proxyport)
http_proxy=http://username:password@yourproxyaddress:proxyport
Useful additional packages
See also
- Repositories/CommandLine
- For further apt-get goodness see PinningHowto.
- AutoDeb
Additional links
- Synaptic Package Manager
- [Apt-howto documentation] also available in package
apt-howto
. - [Community Forums: Installations and Upgrades]