ZZ - Use apt-get To Install, Upgrade, Search, Remove Packages

3 篇文章 0 订阅

ZZ- from http://www.lainoox.com/apt-get-packages/ 


Use apt-get To Install, Upgrade, Search, Remove Packages



One of the main reasons I am a fan of Debian and Ubuntu is for the apt-get package management interface. This allows a user to start from a bare-bones system and manually add and remove packages based on user preference. You are able to update your system, search for packages with the simple commands. Whenever I am in Windows I always wish I had apt-get!

Where Does Apt Look For Packages?

The apt-get package system refers to the /etc/apt/sources.list fill for all package repository locations. Depending on your distribution this file will be larger or smaller. If you are looking for a package that is in another repository you must add the location into this file, then perform a ‘apt-get update’, this will query all repositories for their current package listing. Lets take a quick look at the the sources.list file.

# cat /etc/apt/sources.list
--
# deb cdrom:[Kubuntu 9.10 _Karmic Koala_ - Release amd64 (20091027)]/ karmic main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
 
deb http://ca.archive.ubuntu.com/ubuntu/ lucid main restricted
deb-src http://ca.archive.ubuntu.com/ubuntu/ lucid main restricted
 
## Major bug fix updates produced after the final release of the
## distribution.
deb http://ca.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb-src http://ca.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
 
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu karmic partner
# deb-src http://archive.canonical.com/ubuntu karmic partner
 
deb http://security.ubuntu.com/ubuntu lucid-security main restricted
deb-src http://security.ubuntu.com/ubuntu lucid-security main restricted
deb http://security.ubuntu.com/ubuntu lucid-security universe
deb-src http://security.ubuntu.com/ubuntu lucid-security universe
deb http://security.ubuntu.com/ubuntu lucid-security multiverse
deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse


As you can see, there is a huge set of locations.


Search For Packages With ‘apt-cache search’

Sometimes I know the general package name, or know I need some development packages but am not quite sure what other pieces I need. In some cases I have just finished installing a package from source and during the configuration section I am told I need a certain library or a specific C header file that is part of such and such package. If this is the case then I can easily search for the package using apt-cache search [package name]. After running this command a set of packages with their description is displayed, for example lets have a look for Apache related material. It should be noted, package management affects the entire system and thus sudo or root access is required to use apt-*.

cache search ^Apache
libapache-mod-auth-kerb - apache module for Kerberos authentication
libapache2-mod-auth-kerb - apache2 module for Kerberos authentication
libapache2-mod-auth-mysql - Apache 2 module for MySQL authentication
libapache2-mod-axis2c - Apache web services engine - apache module
libaxiom-java - Apache AXIOM Java library (AXIs Object Model)
libaxis2c-dev - Apache web services engine - Development
libaxis2c-doc - Apache web services engine - Documentation
libaxis2c0 - Apache web services engine - Runtime
librampart-dev - Apache web services security engine - Development
librampart-doc - Apache web services security engine - Documentation
librampart0 - Apache web services security engine - Runtime
libwss4j-java - Apache WSS4J WS-Security implementation
apachetop - Realtime Apache monitoring tool
libapache-authznetldap-perl - Apache-Perl module that enables to authorize a user with LDAP attributes
libapache-gallery-perl - Apache module to create galleries on-the-fly
libapache2-authcassimple-perl - Apache2 module to authentificate trough a CAS server
libapache2-mod-antiloris - Apache2 module to defend against DoS attacks using incomplete requests
libapache2-mod-auth-radius - Apache 2.x module for RADIUS authentication
libapache2-mod-encoding - Apache2 module for non-ascii filename interoperability
libapache2-mod-gnutls - Apache module for SSL and TLS encryption with GnuTLS
libapache2-mod-jk - Apache 2 connector for the Tomcat Java servlet engine
libapache2-mod-layout - Apache web page content wrapper
libapache2-mod-ldap-userdir - Apache module that provides UserDir lookups via LDAP
libapache2-mod-mime-xattr - Apache2 module to get MIME info from filesystem extended attributes
libapache2-mod-mono - Apache module for running ASP.NET applications on Mono
libapache2-mod-neko - Apache module for running server-side Neko programs
libapache2-mod-proxy-html - Apache2 filter module for HTML links rewriting
libapache2-mod-scgi - Apache module implementing the SCGI protocol
libapache2-mod-spamhaus - Apache DNSBL module that blocks listed IP addresses
libapache2-mod-speedycgi - apache2 module to speed up perl scripts by making them persistent
libapache2-mod-suphp - Apache2 module to run php scripts with the owner permissions
libapache2-mod-vhost-ldap - Apache 2 module for Virtual Hosting from LDAP
libapache2-redirtoservname - Apache 2 module to redirect users to the canonical hostname
libapache2-webauth - Apache 2 modules for WebAuth authentication
libapache2-webkdc - Apache 2 modules for a WebAuth authentication KDC
libaxis2c-bin - Apache web services engine - Misc. binaries
rt3.8-apache2 - Apache 2 specific files for request-tracker3.8
libapache2-mod-fastcgi - Apache 2 FastCGI module for long-running CGI scripts
apache2 - Apache HTTP Server metapackage
apache2-doc - Apache HTTP Server documentation
apache2-mpm-event - Apache HTTP Server - event driven model
apache2-mpm-prefork - Apache HTTP Server - traditional non-threaded model
apache2-mpm-worker - Apache HTTP Server - high speed threaded model
apache2-prefork-dev - Apache development headers - non-threaded MPM
apache2-threaded-dev - Apache development headers - threaded MPM
apache2-utils - utility programs for webservers
apache2.2-bin - Apache HTTP Server common binary files
apache2.2-common - Apache HTTP Server common files
apache2-mpm-itk - multiuser MPM for Apache 2.2
apache2-suexec - Standard suexec program for Apache 2 mod_suexec
apache2-suexec-custom - Configurable suexec program for Apache 2 mod_suexec


As you can see, any package name or description with the word Apache in it, is displayed. One of the benefits of using apt-get is that if I were to install ‘apache2′, apt will automatically install any other packages that ‘apache2′ relies upon. This way I do not have to manually select all additional packages – for the most part.


Install A Package With ‘apt-get install [package name]‘

Lets say I want to run a web server and host my own website. You can use the Apache web server to do so. To install the package simply:

# apt-get install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  nvidia-185-kernel-source libfreebob0 libtdb1 libass3 nvidia-185-libvdpau libcanberra0 libcdio7 libx264-67 libiec61883-0 libcelt0 xulrunner-1.9.1 libffado1 firefox-3.5-branding libsmi2-common libfaad0
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libssl-dev libssl0.9.8
Suggested packages:
  apache2-doc apache2-suexec apache2-suexec-custom
The following NEW packages will be installed:
  apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libaprutil1-dbd-sqlite3 libaprutil1-ldap
The following packages will be upgraded:
  libaprutil1 libssl-dev libssl0.9.8
3 upgraded, 7 newly installed, 0 to remove and 458 not upgraded.
Need to get 6,454kB of archives.
After this operation, 10.7MB of additional disk space will be used.
Do you want to continue [Y/n]?


Wow, quite handy. As you can see apt has recognized unused packages, packages that are suggested, as well as packages that will be upgraded during the ‘apache2′ install. It does all the heavy lifting for you. If you select ‘Y’, then apt will download and install the ‘apache2′ (in this case) packages for you.

Get:1 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main libssl-dev 0.9.8k-7ubuntu8.6 [2,144kB]
Get:2 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main libssl0.9.8 0.9.8k-7ubuntu8.6 [980kB]                                                                                                           
Get:3 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main libaprutil1 1.3.9+dfsg-3ubuntu0.10.04.1 [91.1kB]                                                                                                
Get:4 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main libaprutil1-dbd-sqlite3 1.3.9+dfsg-3ubuntu0.10.04.1 [28.2kB]                                                                                    
Get:5 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main libaprutil1-ldap 1.3.9+dfsg-3ubuntu0.10.04.1 [25.8kB]                                                                                           
Get:6 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2.2-bin 2.2.14-5ubuntu8.4 [2,730kB]                                                                                                       
Get:7 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2-utils 2.2.14-5ubuntu8.4 [161kB]                                                                                                         
Get:8 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2.2-common 2.2.14-5ubuntu8.4 [290kB]                                                                                                      
Get:9 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2-mpm-worker 2.2.14-5ubuntu8.4 [2,366B]                                                                                                   
Get:10 http://ca.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2 2.2.14-5ubuntu8.4 [1,478B]                                                                                                             
Fetched 6,454kB in 17s (364kB/s)                                                                                                                                                                              
Preconfiguring packages ...
(Reading database ... 208085 files and directories currently installed.)
Preparing to replace libssl-dev 0.9.8k-7ubuntu8 (using .../libssl-dev_0.9.8k-7ubuntu8.6_amd64.deb) ...
Unpacking replacement libssl-dev ...
Preparing to replace libssl0.9.8 0.9.8k-7ubuntu8 (using .../libssl0.9.8_0.9.8k-7ubuntu8.6_amd64.deb) ...
Unpacking replacement libssl0.9.8 ...
Processing triggers for man-db ...
Setting up libssl0.9.8 (0.9.8k-7ubuntu8.6) ...
 
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
(Reading database ... 208088 files and directories currently installed.)
Preparing to replace libaprutil1 1.3.9+dfsg-3build1 (using .../libaprutil1_1.3.9+dfsg-3ubuntu0.10.04.1_amd64.deb) ...
Unpacking replacement libaprutil1 ...


Remove Packages With ‘apt-get remove [package name]‘

Perhaps you decide you want to use lighttpd instead of apache2. How do we get rid of the package and all of its support packages? Luckily ‘apt-get remove [package name]‘ will do all the heavy lifting for this as well.

# apt-get remove apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  nvidia-185-kernel-source libfreebob0 apache2-mpm-worker libtdb1 libass3 libaprutil1-ldap nvidia-185-libvdpau libcanberra0 apache2-utils libcdio7 libx264-67 libiec61883-0 apache2.2-common libcelt0
  libaprutil1-dbd-sqlite3 xulrunner-1.9.1 apache2.2-bin libffado1 firefox-3.5-branding libsmi2-common libfaad0
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  apache2
0 upgraded, 0 newly installed, 1 to remove and 458 not upgraded.
After this operation, 36.9kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 208643 files and directories currently installed.)
Removing apache2 ...


Voila! Package removed.


Update Package Listings

If you want to update your current package list:

 
$ apt-get update

Apt-Get Options

There are also a set of flags that can be used to only download a package, avoid queries (the Y/N option), show upgraded packages. The options include:

 
Options:
  -h  This help text.
  -q  Loggable output - no progress indicator
  -qq No output except for errors
  -d  Download only - do NOT install or unpack archives
  -s  No-act. Perform ordering simulation
  -y  Assume Yes to all queries and do not prompt
  -f  Attempt to correct a system with broken dependencies in place
  -m  Attempt to continue if archives are unlocatable
  -u  Show a list of upgraded packages as well
  -b  Build the source package after fetching it
  -V  Show verbose version numbers
  -c=? Read this configuration file
  -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp

The command be be paired with the install, remove, etc.

 
# apt-get -d install apache2 [ download only - do not install package ]

This allows you to customize the main function.

Hopefully this gives you a basic working knowledge of the main uses of apt.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值