Tải bản đầy đủ - 0 (trang)
Hack 54. Manage Packages from the Command Line

Hack 54. Manage Packages from the Command Line

Tải bản đầy đủ - 0trang

packageondiskcalledprogram-1.0-1.debthatyouwantto

install,dpkgisthetooltouse.Becauseit'ssuchanimportant

partofthepackage-managementstack,ithasawholehackof

itsown[Hack#57].



aptandFriends

Whileitwasnotoriginallyintendedasafrontendtool,but

ratherasanintermediatelayerbetweendpkgandend-user

toolssuchasSynapticandAdept,runningaptdirectlyis

probablythemostcommonmethodformanagingpackageson

thecommandline.

Somecommandsrequirerootprivileges,soyouneedto

prependthemwithsudoifyou'rerunningasanunprivileged

user.

Herearesomecommandsyou'llwonderhowyoueverlived

without:



Retrievethecurrentlistofpackagesfromallservers

Ifyoudon'tdothisfromtimetotime,yourlocallistof

availablepackagesmaybecomeoutofdate.Runthis

commandoccasionallybeforedoingadist-upgradeor

searchingforanewpackage.Thepackagelistsarelarge,

anddoinganupdatemayresultinseveralMBofdatabeing

retrievedfromtheInternet:

$sudoapt-getupdate





Doakeywordsearch

Thesearchcommandsearchesthroughthelistofavailable

packages,includingpackagenamesanddescriptions.You

canuseseveralkeywords;forexample,apt-cachesearchtext

editorfindsalistoftexteditors:

$apt-cachesearch



keywords







Getmoreinformation

Onceyou'vefoundapackagethatlooksinterestingusing

apt-cachesearch,youcandisplaymoredetailedinformation

aboutitusingapt-cacheshowprogram.Thiswilltellyouthings

likethesizeofthepackage(importantifyouareinstallingit

viatheInternet)andanextendeddescription,aswellas

whatotherpackagesitdependsoninordertoworkandthe

nameofthedeveloperwhomaintainsthepackage:

$apt-cacheshow



program







Installapackage

Thiswillgetthelatestversionofthespecifiedpackageand

installit,alongwithanyotherpackagesthatitdependson



inordertowork.Iftherequestedpackageisalready

installed,thiswillupgradeittothelatestavailableversion:

$sudoapt-getinstall



program







Removeaprogram

Ifyou'vepreviouslyinstalledaprogramanddecideyou

don'twantitanymore,youcanremoveitusingthis

command.Becausesomesoftwarepackagescandependon

others,removingoneprogrammaybreakotherprograms.

Runningapt-getremovethereforechecksfirsttoseeifany

othersoftwareprogramsneedtheprogramtowork,and

offerstouninstallthemaswell.Thisisjustoneexampleof

thewaytheUbuntupackage-managementtoolshavebeen

designedtotrytokeepyourcomputerinasanestate,

withoutbrokenorhalf-installedsoftware.It'scertainly

possibletobreakanUbuntusystem,butgenerallyyouhave

totrytodoit.Theremovecommandalsohasa--purge

optionthatremovesnotjusttheprogramitselfbutalsoall

configurationfilesassociatedwithit:

$sudoapt-getremove



program



$sudoapt-getremove--purge



program







Upgradeyoursystem

Overtime,mostofthesoftwarepackagesonyourcomputer

willbecomeoutofdate,asnewversionsarereleasedto

addfeaturesorfixbugs.Youcouldmanuallydoapt-get

installfoooneachone,butthat'snotveryconvenient,so

aptprovidesasimplewaytoupgradeyourentiresystemat

once.Justtypeapt-getupgradetohaveaptcheckeverysingle

packageonyoursystemforanewversionandthen

downloadandinstallit.Thiscommandwillneverinstallnew

packages;itwillonlyupgradepackagesthatarealready

installed:

$sudoapt-getupgrade





Performafullupgrade

Sometimes,you'llhaveasoftwarepackageinstalled,anda

newversionwillcomeoutthathasalotofnewfeaturesand

thereforenowdependsonsomeotherprogramtorun.For

example,youmayhaveamovieplayerinstalledthat

supportsalotofdifferentmovieformats.Whennew

formatscomeout,modulesforthoseformatsmaybeadded

inseparatepackages,sothelatestversionofthemovieplayersoftwarenowdependsonanewpackagethatyou

don'tyethaveinstalledonyoursystem.Ifyoujustrunaptgetupgrade,you'llgetthelatestmovieplayer,butyouwon't

getallthenewmovie-formatpackages.Theapt-getdistupgradecommandsolvesthatproblemforyou:notonlydoes

itgetthelatestversionofeverypackagealreadyinstalled

justlikeapt-getupgrade,italsoinstallsanynewpackages



theyneedthatmaynotbeonyoursystemyet.Ifyouwant

tokeepyoursystemup-to-datewithallthelatestupdates

andsecuritypatches,runningapt-getupdate;apt-getdistupgradefromtimetotimeisthebestwaytodoit:

$sudoapt-getdist-upgrade





Cleanup

Whenyouaskapttoinstallasoftwarepackage,it

downloadsthepackageandstoresitinacacheonyourdisk

beforeitdoestheactualinstallation.Ifyouthenremovethe

packagebutlaterchangeyourmindagainandreinstallit,

aptdoesn'tneedtofetchitfromtheInternetagainbecause

thepackageissittinginthelocalcache.That'sgreatfor

savingbandwidth,butafterawhile,thecachecanuseup

spaceonyourdisk,soit'sagoodideatoperiodicallydelete

oldpackagesfromit.Runningapt-getcleanwilltotallyflush

thepackagecache,possiblyfreeingupsomepreciousdisk

space.Thiscommandisquitesafebecausetheworstthat

canhappenisaptmayneedtodownloadapackageagainif

youremoveitandthenreinstallit:

$sudoapt-getclean





Cleansmarter

autocleanisalmostthesameasclean,exceptit'sjustalittle



bitsmarter:insteadofcleaningoutyourentirepackage

cache,itdeletesonlysupersededpackages.Forexample,



yourpackagecachemaycontainpackagesforthelastfour

versionsofatexteditorthathasbeenupgradedanumber

oftimes.Runningapt-getautocleanwilldeletetheoldest

threeversionsfromthecache,leavingonlythelatestone.

Thatmakessensebecauseyou'renotlikelytoreinstall

anythingexceptthelatestversionanyway:

$sudoapt-getautoclean





Lazylikeafox

Ifyouspendalotoftimeworkingonthecommandline,you

canmakethingseasierforyourselfbycreatingshortcutsforthe

commoncommands.Addtheselinestoyour~/.bashrc:

aliasagi='sudoapt-getinstall'

aliasagu='sudoapt-getupdate'

aliasags='apt-cachesearch'

aliasagsh='apt-cacheshow'

aliasagr='sudoapt-getremove'

aliasagd='sudoapt-getdist-upgrade'



Thenyouwon'tneedtotypethewholecommand.Todoa

search,forexample,justtypeagsfooandenteryourpasswordif

required.Lazinessisavirtue!



Hack55.ManagePackageswithSynaptic



UsethedefaultUbuntupackagemanagertoeasilyinstall

andupdateprogramsonyoursystem.

Onethingthatcanbedifficulttogetusedtoifyouarenewto

Linuxispackagemanagement.Ononehand,thewaythat

Ubuntuhandlesprograminstallationandupgradingismuch

simplerthanonotheroperatingsystems.Ontheotherhand,

it'sratherdifferentfromwhatyoumightbeusedto,soittakes

sometimetolearntheinsandouts.Luckily,allyouneedto

learnisasingletoolandyoucanthenapplythatknowledgeto

installandupgradeanyofthousandsofUbuntuprograms.In

thishack,wetalkabouthowtousethedefaultUbuntupackage

managercalledSynaptictomanageallofUbuntu'spackages

efficientlyandeasily.

ThefirststepistostartSynaptic.ClickSystem Administration

SynapticPackageManagertolaunchtheprogram.Synaptic

requiresrootprivilegestorun,soyouwillbepromptedforyour

passwordwhenitstarts.Figure6-1showsthedefaultinterface,

whichhasalotofinformationonit,butonceyouarefamiliar

withitsfunctions,you'llfindit'snottoodifficulttonavigate.



Figure6-1.ThedefaultSynapticwindow



Themainwindowisdividedintoafewsections.Thesidebar

displaysthedifferentpackagecategoriessothatyoucan

quicklydrilldowntoaparticulargroupofpackages(likegames)

andnothavetoreadthroughpackagesinothercategories.The

firstcategory,All,displaysallpackages.Ontherightsideofthe

windowalongthetopisthelistofpackages,alongwith

informationaboutwhethertheyareinstalledandwhatthe

latestversionis.Ifyouselectaparticularpackage,detailed

informationisdisplayedinthepanebelow.Nearthetopofthe

screenareafewbuttonsthatcorrespondtothemainactions

you'llwanttoperformwhenusingSynaptic,describednext.



ReloadthePackageList

InUbuntu,packagesresideinwhatareknownaspackage

repositories."ModifytheListofPackageRepositories"[Hack

#60]goesintomoredetailaboutthedifferentpackage

repositoriesthatexistforUbuntu,butinshort,these



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 54. Manage Packages from the Command Line

Tải bản đầy đủ ngay(0 tr)

×