特殊:Badtitle/NS100:AptGetHowto:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第1行: | 第1行: | ||
{{From|https://help.ubuntu.com/community/AptGetHowto}} | {{From|https://help.ubuntu.com/community/AptGetHowto}} | ||
{{Languages|UbuntuHelp:AptGetHowto}} | {{Languages|UbuntuHelp:AptGetHowto}} | ||
== | == Packa<pre><nowiki>man</nowiki></pre>ment with apt == | ||
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconApt.png | https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconApt.png | ||
Package management via apt- | Package management via apt-ge<pre><nowiki>un</nowiki></pre>and-in-hand with the sources.list file. For information on editing or updating that files entries, see [[UbuntuHelp:SourcesList|SourcesList]] | ||
=== Intro === | === Intro === | ||
''"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.'' | ''"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.'' | ||
第11行: | 第11行: | ||
All these commands require [[UbuntuHelp:RootSudo|sudo]]. Replace "packagename" or "string" with the program you're installing or searching for. | All these commands require [[UbuntuHelp:RootSudo|sudo]]. Replace "packagename" or "string" with the program you're installing or searching for. | ||
==== Installation ==== | ==== Installation ==== | ||
*< | *<pre><nowiki>apt-get install packagename</nowiki></pre> - installs a new package (but s<pre><nowiki>aptitude</nowiki></pre>elow) | ||
*<code><nowiki>aptitude</nowiki></code> - Curses viewer of packages installed or available. Aptitude can be used from the command-line in a similar way to apt-get, but only for some commands - install and remove being the most common. However, because aptitude keeps track of more information than apt-get does, it can be considered better at install and remove operations. | *<code><nowiki>aptitude</nowiki></code> - Curses viewer of packages installed or available. Aptitude can be used from the command-line in a similar way to apt-get, but only for some commands - install and remove being the most common. However, because aptitude keeps track of more information than apt-get does, it can be considered better at install and remove operations. | ||
==== Maintenance ==== | ==== Maintenance ==== | ||
*< | *<pre><nowiki>apt-get update</nowiki></pre> -- Run this after changing /etc/apt/sources.list or /etc/apt/preferences. You also must run it periodically to make sure your source list is up-to-date. This is the equivalent of “reload” in Synaptic, or “check for updates” in Windows or OS X. | ||
*< | *<pre><nowiki>apt-get upgrade</nowiki></pre> -- upgrades all installed packages. This is the equivalent of “mark all upgrades” and “apply” in Synaptic in one step. | ||
*< | *<pre><nowiki>apt-get dist-upgrade</nowiki></pre> - upgrades the entire system to a newer release. The same as the above, except add the “smart upgrade” checkbox -- i.e. tell APT to do whatever it has to do to upgrade to the latest packages, even if it means removing some other packages. (NB this is not a recommended way of upgrading to a new release) | ||
*< | *<pre><nowiki>apt-get -f install</nowiki></pre> -- the same as “Edit->Fix Broken Packages” and “Apply” in synaptic. Do this if you get complaints about packages with “unmet dependences”. | ||
*< | *<pre><nowiki>apt-get autoclean</nowiki></pre> - Run this periodically to clean out .deb archives from packages which are no longer installed on the system. You can regain lots of disk space that way. If you're really desperate for disk space, <pre><nowiki>apt-get clean</nowiki></pre> is more radical, and will remove .deb files even for packages currently installed. But most of the time you probably don't need the .debs any more, so it might be worth it if you're strapped for megabytes. | ||
*< | *<pre><nowiki>apt-get clean</nowiki></pre> -- the same as above, except remove *all* packages from the package cache. Usually you don’t need them, so this is smart if you’re running low on disk space. If you’re on dial-up, you might reconsider. | ||
*The package cache is in /var/cache/apt/archives, so "du -sh /var/cache/apt/archives" will tell you how much space cached packages are taking up. | *The package cache is in /var/cache/apt/archives, so "du -sh /var/cache/apt/archives" will tell you how much space cached packages are taking up. | ||
*< | *<pre><nowiki>dpkg-reconfigure foo</nowiki></pre> -- reconfigure package ”foo“. You really want to know this one. With many packages, you’ll be prompted with some configuration questions you may not have known were there. For exampl<pre><nowiki>dpkg-reconfigure</nowiki></pre>ntconfig-config will present you with a ”wizard“ on configuring fonts in Ubuntu. I run this one on every Ubuntu install I do, because I want to make bitmapped fonts available to all my apps. | ||
* <code><nowiki>dpkg-reconfigure</nowiki></code>, like the name says, is for *reconfiguring* packages -- if you’ve installed a package that’s asked you questions, and you’d like to change some of those answers, this is what you’re looking for. | * <code><nowiki>dpkg-reconfigure</nowiki></code>, like the name says, is for *reconfiguring* packages -- if you’ve installed a package that’s asked you questions, and you’d like to change some of those answers, this is what you’re looking for. | ||
*< | *<pre><nowiki>echo</nowiki></pre> "foo hold" | dpkg --set-selectons -- place package "foo" on hold, i.e. don't upgrade this package, even if it means holding back loads of upgrades that depend on the upgraded version. This is the same as Synaptic's "Package->Lock Version" | ||
* Note that < | * Note that <pre><nowiki>apt-get dist-upgrade</nowiki></pre> will override this, but will warn you first. Also, if you want to use this with sudo, you nee<pre><nowiki>echo</nowiki></pre>oo hold" | sudo dpkg --set-selections' and not 'sudo echo "foo hold" | dpkg --set-selections'. | ||
*<code><nowiki>echo</nowiki></code> "foo install" -- remove the "hold" or "locked package" state set above. The same thing with sudo applies, i.e. it's 'echo "foo install" | sudo dpkg --set-selections' | *<code><nowiki>echo</nowiki></code> "foo install" -- remove the "hold" or "locked package" state set above. The same thing with sudo applies, i.e. it's 'echo "foo install" | sudo dpkg --set-selections' | ||
==== Removal ==== | ==== Removal ==== | ||
*< | *<pre><nowiki>apt-get remove packagename</nowiki></pre> - removes a installed package (configfiles remain) | ||
*< | *<pre><nowiki>apt-get --purge remove packagename</nowiki></pre> - removes a installed package (configfiles will also be removed) | ||
* A special trick: if you want to remove package “foo” and install package “bar” in one step: < | * A special trick: if you want to remove package “foo” and install package “bar” in one step: <pre><nowiki>apt-get --purge remove foo bar+</nowiki></pre>. | ||
*< | *<pre><nowiki>apt-get autoremove packagename</nowiki></pre> - removes a installed package and dependencies | ||
==== Searching ==== | ==== Searching ==== | ||
*< | *<pre><nowiki>apt-cache search foo</nowiki></pre> -- find packages that include “foo”. | ||
*< | *<pre><nowiki>dpkg -l ’*foo*‘</nowiki></pre> -- find packages whose names contain “foo”. Similar to <pre><nowiki>apt-cache search foo</nowiki></pre>, but also shows whether package is installed on your system by marking with <pre><nowiki>ii</nowiki></pre> (installed) and <code><nowiki>un</nowiki></code> (not installed). | ||
*< | *<pre><nowiki>apt-cache show foo</nowiki></pre> -- shows the description of package “foo" and other relevant information including version, size, dependencies and conflicts. | ||
*dpkg --print-avail -- similar to above. | *dpkg --print-avail -- similar to above. | ||
*< | *<pre><nowiki>dpkg -L package</nowiki></pre> - List files in the package. Used also (?) to determine what files the “foo” package has installed on your system. This is *very* useful. | ||
*< | *<pre><nowiki>dpkg -c foo.deb</nowiki></pre> -- List files in the package "foo.deb". Note that foo.deb is a pathname -- this is for .deb packages you’ve downloaded by hand. | ||
*< | *<pre><nowiki>dlocate foo</nowiki></pre> -- Determines Which installed package owns foo. dlocate shows files from installed packages that match “foo”, with the name of the package they came from. This is sort of the inverse of the above, and is useful for answering the question “What package did this file come from?“ You have to have the dlocate package installed for this to work. | ||
*< | *<pre><nowiki>dpkg -S foo</nowiki></pre> -- Like the above, but much slower. It’ll work on any Debian or Ubuntu system, i.e. it doesn’t require that dlocate be installed. | ||
*< | *<pre><nowiki>apt-file search foo</nowiki></pre> -- like dlocate and dpkg -S, but searches all available packages, not just the ones that are installed on your system -- i.e. it answers the question ”what package provides this file?“. You’ll have to install the apt-file package first, and keep the apt-file database up to date (i.e. you have to do apt-file update just like you do apt-get update). | ||
*< | *<pre><nowiki>apt-cache pkgnames</nowiki></pre> - Fast listing of every package in the 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 < | *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 <pre><nowiki>grep</nowiki></pre>. Examples: | ||
*< | *<pre><nowiki>apt-cache search filename | grep -w filename</nowiki></pre> - shows only the files that contain filename as a whole word | ||
*< | *<pre><nowiki>dpkg -L package | grep /usr/bin </nowiki></pre> - list files located in directories like /bin or /usr/bin, useful if you're looking for a particular executable | ||
For more information on apt-get, apt-cache and dpkg consult their manual pages by using the <code><nowiki>man</nowiki></code> command. These manuals will provide a wider scope of information in addition to all of the options that you can use with each program. | For more information on apt-get, apt-cache and dpkg consult their manual pages by using the <code><nowiki>man</nowiki></code> command. These manuals will provide a wider scope of information in addition to all of the options that you can use with each program. | ||
Example: < | Example: <pre><nowiki>man apt-get</nowiki></pre>. | ||
=== Typical use case === | === Typical use case === | ||
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? | 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? | ||
第77行: | 第77行: | ||
apt-get remove --purge torcs</nowiki></pre> | apt-get remove --purge torcs</nowiki></pre> | ||
=== Additional packages === | === Additional packages === | ||
< | <pre><nowiki>deborphan</nowiki></pre> and <pre><nowiki>debfoster</nowiki></pre> are great for finding orphaned and unneeded packages which can be removed. | ||
=== Speeding up your work at the command line === | === Speeding up your work at the command line === | ||
You can create aliases to make typing these commands faster. For example, you might put this in your *~/.bashrc* | You can create aliases to make typing these commands faster. For example, you might put this in your *~/.bashrc* | ||
<pre><nowiki> | <pre><nowiki> | ||
alias acs='apt-cache search' | alias acs='apt-cache search' | ||
alias agu='sudo apt-get update' | alias agu='sudo apt-get update' | ||
alias agg='sudo apt-get upgrade' | alias agg='sudo apt-get upgrade' | ||
alias agd='sudo apt-get dist-upgrade' | alias agd='sudo apt-get dist-upgrade' | ||
alias agi='sudo apt-get install' | alias agi='sudo apt-get install' | ||
alias agr='sudo apt-get remove'</nowiki></pre> | alias agr='sudo apt-get remove'</nowiki></pre> | ||
But see aptitude, above, for a reason to use "alias agi='sudo aptitude install'" | But see aptitude, above, for a reason to use "alias agi='sudo aptitude install'" | ||
=== Setting up apt-get to use a http-proxy === | === Setting up apt-get to use a http-proxy === | ||
第116行: | 第116行: | ||
If you make a mistake and go back to edit the file again, remember to close the terminal and reopen it. It will not function with the new settings until you do. | If you make a mistake and go back to edit the file again, remember to close the terminal and reopen it. It will not function with the new settings until you do. | ||
=== Links === | === Links === | ||
* [http://www.debian.org/doc/ | * [http://www.debian.org/doc/manua<pre><nowiki>apt-howto</nowiki></pre>dex.en.html Debian Apt-howto documentation] also available in package <code><nowiki>apt-howto</nowiki></code>. | ||
* For further apt-get goodness see [[UbuntuHelp:PinningHowto|PinningHowto]]. | * For further apt-get goodness see [[UbuntuHelp:PinningHowto|PinningHowto]]. | ||
---- | ---- |
2007年12月6日 (四) 10:04的版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/AptGetHowto }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/af | • {{#if: UbuntuHelp:AptGetHowto|Afrikaans| [[::AptGetHowto/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/ar | • {{#if: UbuntuHelp:AptGetHowto|العربية| [[::AptGetHowto/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/az | • {{#if: UbuntuHelp:AptGetHowto|azərbaycanca| [[::AptGetHowto/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/bcc | • {{#if: UbuntuHelp:AptGetHowto|جهلسری بلوچی| [[::AptGetHowto/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/bg | • {{#if: UbuntuHelp:AptGetHowto|български| [[::AptGetHowto/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/br | • {{#if: UbuntuHelp:AptGetHowto|brezhoneg| [[::AptGetHowto/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/ca | • {{#if: UbuntuHelp:AptGetHowto|català| [[::AptGetHowto/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/cs | • {{#if: UbuntuHelp:AptGetHowto|čeština| [[::AptGetHowto/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/de | • {{#if: UbuntuHelp:AptGetHowto|Deutsch| [[::AptGetHowto/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/el | • {{#if: UbuntuHelp:AptGetHowto|Ελληνικά| [[::AptGetHowto/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/es | • {{#if: UbuntuHelp:AptGetHowto|español| [[::AptGetHowto/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/fa | • {{#if: UbuntuHelp:AptGetHowto|فارسی| [[::AptGetHowto/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/fi | • {{#if: UbuntuHelp:AptGetHowto|suomi| [[::AptGetHowto/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/fr | • {{#if: UbuntuHelp:AptGetHowto|français| [[::AptGetHowto/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/gu | • {{#if: UbuntuHelp:AptGetHowto|ગુજરાતી| [[::AptGetHowto/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/he | • {{#if: UbuntuHelp:AptGetHowto|עברית| [[::AptGetHowto/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/hu | • {{#if: UbuntuHelp:AptGetHowto|magyar| [[::AptGetHowto/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/id | • {{#if: UbuntuHelp:AptGetHowto|Bahasa Indonesia| [[::AptGetHowto/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/it | • {{#if: UbuntuHelp:AptGetHowto|italiano| [[::AptGetHowto/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/ja | • {{#if: UbuntuHelp:AptGetHowto|日本語| [[::AptGetHowto/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/ko | • {{#if: UbuntuHelp:AptGetHowto|한국어| [[::AptGetHowto/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/ksh | • {{#if: UbuntuHelp:AptGetHowto|Ripoarisch| [[::AptGetHowto/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/mr | • {{#if: UbuntuHelp:AptGetHowto|मराठी| [[::AptGetHowto/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/ms | • {{#if: UbuntuHelp:AptGetHowto|Bahasa Melayu| [[::AptGetHowto/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/nl | • {{#if: UbuntuHelp:AptGetHowto|Nederlands| [[::AptGetHowto/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/no | • {{#if: UbuntuHelp:AptGetHowto|norsk| [[::AptGetHowto/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/oc | • {{#if: UbuntuHelp:AptGetHowto|occitan| [[::AptGetHowto/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/pl | • {{#if: UbuntuHelp:AptGetHowto|polski| [[::AptGetHowto/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/pt | • {{#if: UbuntuHelp:AptGetHowto|português| [[::AptGetHowto/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/ro | • {{#if: UbuntuHelp:AptGetHowto|română| [[::AptGetHowto/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/ru | • {{#if: UbuntuHelp:AptGetHowto|русский| [[::AptGetHowto/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/si | • {{#if: UbuntuHelp:AptGetHowto|සිංහල| [[::AptGetHowto/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/sq | • {{#if: UbuntuHelp:AptGetHowto|shqip| [[::AptGetHowto/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/sr | • {{#if: UbuntuHelp:AptGetHowto|српски / srpski| [[::AptGetHowto/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/sv | • {{#if: UbuntuHelp:AptGetHowto|svenska| [[::AptGetHowto/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/th | • {{#if: UbuntuHelp:AptGetHowto|ไทย| [[::AptGetHowto/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/tr | • {{#if: UbuntuHelp:AptGetHowto|Türkçe| [[::AptGetHowto/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/vi | • {{#if: UbuntuHelp:AptGetHowto|Tiếng Việt| [[::AptGetHowto/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/yue | • {{#if: UbuntuHelp:AptGetHowto|粵語| [[::AptGetHowto/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/zh | • {{#if: UbuntuHelp:AptGetHowto|中文| [[::AptGetHowto/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/zh-hans | • {{#if: UbuntuHelp:AptGetHowto|中文(简体)| [[::AptGetHowto/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptGetHowto | UbuntuHelp:AptGetHowto | {{#if: | :}}AptGetHowto}}/zh-hant | • {{#if: UbuntuHelp:AptGetHowto|中文(繁體)| [[::AptGetHowto/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:AptGetHowto|:AptGetHowto|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :AptGetHowto/zh | | {{#ifexist: AptGetHowto/zh | | {{#ifeq: {{#titleparts:AptGetHowto|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:AptGetHowto|1|-1|}} | zh | | }}
Packaman
ment with apt
Package management via apt-ge
un
and-in-hand with the sources.list file. For information on editing or updating that files entries, see SourcesList
Intro
"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
All these commands require sudo. Replace "packagename" or "string" with the program you're installing or searching for.
Installation
apt-get install packagename
- installs a new package (but saptitude
elow)aptitude
- Curses viewer of packages installed or available. Aptitude can be used from the command-line in a similar way to apt-get, but only for some commands - install and remove being the most common. However, because aptitude keeps track of more information than apt-get does, it can be considered better at install and remove operations.
Maintenance
apt-get update
-- Run this after changing /etc/apt/sources.list or /etc/apt/preferences. You also must run it periodically to make sure your source list is up-to-date. This is the equivalent of “reload” in Synaptic, or “check for updates” in Windows or OS X.apt-get upgrade
-- upgrades all installed packages. This is the equivalent of “mark all upgrades” and “apply” in Synaptic in one step.apt-get dist-upgrade
- upgrades the entire system to a newer release. The same as the above, except add the “smart upgrade” checkbox -- i.e. tell APT to do whatever it has to do to upgrade to the latest packages, even if it means removing some other packages. (NB this is not a recommended way of upgrading to a new release)apt-get -f install
-- the same as “Edit->Fix Broken Packages” and “Apply” in synaptic. Do this if you get complaints about packages with “unmet dependences”.apt-get autoclean
- Run this periodically to clean out .deb archives from packages which are no longer installed on the system. You can regain lots of disk space that way. If you're really desperate for disk space,apt-get clean
is more radical, and will remove .deb files even for packages currently installed. But most of the time you probably don't need the .debs any more, so it might be worth it if you're strapped for megabytes.apt-get clean
-- the same as above, except remove *all* packages from the package cache. Usually you don’t need them, so this is smart if you’re running low on disk space. If you’re on dial-up, you might reconsider.- The package cache is in /var/cache/apt/archives, so "du -sh /var/cache/apt/archives" will tell you how much space cached packages are taking up.
dpkg-reconfigure foo
-- reconfigure package ”foo“. You really want to know this one. With many packages, you’ll be prompted with some configuration questions you may not have known were there. For exampldpkg-reconfigure
ntconfig-config will present you with a ”wizard“ on configuring fonts in Ubuntu. I run this one on every Ubuntu install I do, because I want to make bitmapped fonts available to all my apps.dpkg-reconfigure
, like the name says, is for *reconfiguring* packages -- if you’ve installed a package that’s asked you questions, and you’d like to change some of those answers, this is what you’re looking for.echo
"foo hold" | dpkg --set-selectons -- place package "foo" on hold, i.e. don't upgrade this package, even if it means holding back loads of upgrades that depend on the upgraded version. This is the same as Synaptic's "Package->Lock Version"- Note that
apt-get dist-upgrade
will override this, but will warn you first. Also, if you want to use this with sudo, you neeecho
oo hold" | sudo dpkg --set-selections' and not 'sudo echo "foo hold" | dpkg --set-selections'. echo
"foo install" -- remove the "hold" or "locked package" state set above. The same thing with sudo applies, i.e. it's 'echo "foo install" | sudo dpkg --set-selections'
Removal
apt-get remove packagename
- removes a installed package (configfiles remain)apt-get --purge remove packagename
- removes a installed package (configfiles will also be removed)- A special trick: if you want to remove package “foo” and install package “bar” in one step:
apt-get --purge remove foo bar+
. apt-get autoremove packagename
- removes a installed package and dependencies
Searching
apt-cache search foo
-- find packages that include “foo”.dpkg -l ’*foo*‘
-- find packages whose names contain “foo”. Similar toapt-cache search foo
, but also shows whether package is installed on your system by marking withii
(installed) andun
(not installed).apt-cache show foo
-- shows the description of package “foo" and other relevant information including version, size, dependencies and conflicts.- dpkg --print-avail -- similar to above.
dpkg -L package
- List files in the package. Used also (?) to determine what files the “foo” package has installed on your system. This is *very* useful.dpkg -c foo.deb
-- List files in the package "foo.deb". Note that foo.deb is a pathname -- this is for .deb packages you’ve downloaded by hand.dlocate foo
-- Determines Which installed package owns foo. dlocate shows files from installed packages that match “foo”, with the name of the package they came from. This is sort of the inverse of the above, and is useful for answering the question “What package did this file come from?“ You have to have the dlocate package installed for this to work.dpkg -S foo
-- Like the above, but much slower. It’ll work on any Debian or Ubuntu system, i.e. it doesn’t require that dlocate be installed.apt-file search foo
-- like dlocate and dpkg -S, but searches all available packages, not just the ones that are installed on your system -- i.e. it answers the question ”what package provides this file?“. You’ll have to install the apt-file package first, and keep the apt-file database up to date (i.e. you have to do apt-file update just like you do apt-get update).apt-cache pkgnames
- Fast listing of every package in the 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: apt-cache search filename | grep -w filename
- shows only the files that contain filename as a whole worddpkg -L package | grep /usr/bin
- list files located in directories like /bin or /usr/bin, useful if you're looking for a particular executable
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.
Example:
man apt-get
.
Typical use case
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 remove --purge torcs
Additional packages
deborphan
and
debfoster
are great for finding orphaned and unneeded packages which can be removed.
Speeding up your work at the command line
You can create aliases to make typing these commands faster. For example, you might put this in your *~/.bashrc*
alias acs='apt-cache search' alias agu='sudo apt-get update' alias agg='sudo apt-get upgrade' alias agd='sudo apt-get dist-upgrade' alias agi='sudo apt-get install' alias agr='sudo apt-get remove'
But see aptitude, above, for a reason to use "alias agi='sudo aptitude install'"
Setting up apt-get to use a http-proxy
These are three methods of using apt-get with a http-proxy. Method 1. 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
Method 2. 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. Note:- 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 apt.conf file (substitute your details for yourproxyaddress and proxyport).
Acquire::http::Proxy "http://yourproxyaddress:proxyport";
Save the apt.conf file. Method 3. 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 Test proxy with sudo apt-get update and whatever networking tool you desire. I use firestarter to see active connections. If you make a mistake and go back to edit the file again, remember to close the terminal and reopen it. It will not function with the new settings until you do.
Links
apt-howto
dex.en.html Debian Apt-howto documentation also available in packageapt-howto
.- For further apt-get goodness see PinningHowto.