20 comandi YUM Linux Yellowdog, Updater, Modified per la gestione dei pacchetti
In questo articolo impareremo 20 comandi YUM per la gestione dei pacchetti Linux. Vedremo come installare, aggiornare, rimuovere, trovare pacchetti, gestire pacchetti e repository su sistemi Linux utilizzando lo strumento YUM (Yellowdog Updater Modified) sviluppato da RedHat. I comandi di esempio mostrati in questo articolo sono praticamente testati su un server VPS CentOS 6.3, è possibile utilizzare questo materiale per scopi di studio, certificazioni o semplicemente per esplorare modi per installare nuovi pacchetti e mantenere il sistema aggiornato. Il requisito di base di questo articolo è che devi avere una conoscenza di base dei comandi e un sistema operativo Linux funzionante, dove puoi esplorare e praticare tutti i comandi elencati di seguito.
Che cos’è YUM?
YUM (Yellowdog Updater Modified) è una riga di comando open source e uno strumento di gestione dei pacchetti basato su grafica per sistemi Linux basati su RPM (RedHat Package Manager). Consente agli utenti e all’amministratore di sistema di installare, aggiornare, rimuovere o cercare facilmente pacchetti software su un sistema. È stato sviluppato e rilasciato da Seth Vidal sotto GPL (General Public License) come open source, significa che chiunque può essere autorizzato a scaricare e accedere al codice per correggere bug e sviluppare pacchetti personalizzati. YUM utilizza numerosi repository di terze parti per installare automaticamente i pacchetti risolvendo i problemi relativi alle dipendenze.
1. Installare un pacchetto con YUM
Per installare un pacchetto chiamato Firefox 14, basta eseguire il comando seguente, che troverà e installerà automaticamente tutte le dipendenze necessarie per Firefox.
# yum install firefox
Loaded plugins: fastestmirror
Dependencies Resolved
================================================================================================ Package Arch Version Repository Size ================================================================================================ Updating: firefox i686 10.0.6-1.el6.centos updates 20 M Updating for dependencies: xulrunner i686 10.0.6-1.el6.centos updates 12 M Transaction Summary ================================================================================================ Install 0 Package(s) Upgrade 2 Package(s) Total download size: 32 M Is this ok [y/N]: y Downloading Packages: (1/2): firefox-10.0.6-1.el6.centos.i686.rpm | 20 MB 01:10 (2/2): xulrunner-10.0.6-1.el6.centos.i686.rpm | 12 MB 00:52 ------------------------------------------------------------------------------------------------ Total 63 kB/s | 32 MB 02:04 Updated: firefox.i686 0:10.0.6-1.el6.centos Dependency Updated: xulrunner.i686 0:10.0.6-1.el6.centos Complete!
Il comando dato sopra chiederà conferma prima di installare qualsiasi pacchetto sul sistema. Se si desidera installare automaticamente i pacchetti senza chiedere alcuna conferma, utilizzare l’opzione -y come illustrato nell’esempio seguente.
# yum -y install firefox
2. Rimozione di un pacchetto con YUM
Per rimuovere completamente un pacchetto con tutte le dipendenze, è necessario eseguire il comando seguente, come illustrato qui sotto.
# yum remove firefox
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package firefox.i686 0:10.0.6-1.el6.centos set to be erased
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================
Package Arch Version Repository Size
====================================================================================================
Removing:
firefox i686 10.0.6-1.el6.centos @updates 23 M
Transaction Summary
====================================================================================================
Remove 1 Package(s)
Reinstall 0 Package(s)
Downgrade 0 Package(s)
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : firefox-10.0.6-1.el6.centos.i686 1/1
Removed:
firefox.i686 0:10.0.6-1.el6.centos
Complete!
Allo stesso modo il comando dato sopra, chiederà conferma prima di rimuovere un pacchetto. Per disabilitare il prompt di conferma basta aggiungere l’opzione -y come mostrato di seguito.
# yum -y remove firefox
3. Aggiornamento di un pacchetto tramite YUM
Supponiamo che tu abbia una versione obsoleta del pacchetto MySQL e che desideri aggiornarlo all’ultima versione stabile. Basta eseguire il comando seguente, risolverà automaticamente tutti i problemi di dipendenze e li installerà.
# yum update mysql
Loaded plugins: fastestmirror
Dependencies Resolved
============================================================================================================
Package Arch Version Repository Size
============================================================================================================
Updating:
vsftpd i386 2.0.5-24.el5_8.1 updates 144 k
Transaction Summary
============================================================================================================
Install 0 Package(s)
Upgrade 1 Package(s)
Total size: 144 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : vsftpd 1/2
Cleanup : vsftpd 2/2
Updated:
vsftpd.i386 0:2.0.5-24.el5_8.1
Complete!
4. Elencare un pacchetto utilizzando YUM
Utilizzare la funzione list per cercare il pacchetto specifico con nome. Ad esempio, per cercare un pacchetto denominato openssh, utilizzare il comando .
# yum list openssh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.neu.edu.cn
* epel: mirror.neu.edu.cn
* extras: mirror.neu.edu.cn
* rpmforge: mirror.nl.leaseweb.net
* updates: mirror.nus.edu.sg
Installed Packages
openssh.i386 4.3p2-72.el5_6.3 installed
Available Packages 4.3p2-82.el5 base
Per rendere la ricerca più accurata, definisci il nome del pacchetto con la loro versione, nel caso in cui tu lo sappia. Ad esempio, per cercare una versione specifica openssh-4.3p2 del pacchetto, utilizzare il comando:
# yum list openssh-4.3p2
5. Cerca un pacchetto usando YUM
Se non ricordi il nome esatto del pacchetto, usa la funzione di ricerca per cercare tutti i pacchetti disponibili in modo che corrispondano al nome del pacchetto specificato. Ad esempio, per cercare tutti i pacchetti che corrispondono alla parola .
# yum search vsftpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.neu.edu.cn
* epel: mirror.neu.edu.cn
* extras: mirror.neu.edu.cn
* rpmforge: mirror.nl.leaseweb.net
* updates: ftp.iitm.ac.in
============================== Matched: vsftpd ========================
ccze.i386 : A robust log colorizer
pure-ftpd-selinux.i386 : SELinux support for Pure-FTPD
vsftpd.i386 : vsftpd - Very Secure Ftp Daemon
6. Ottenere informazioni su un pacchetto utilizzando YUM
Per ottenere informazioni su un pacchetto basta rilasciare il comando seguente:
# yum info firefox
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.neu.edu.cn
* epel: mirror.neu.edu.cn
* extras: mirror.neu.edu.cn
* rpmforge: mirror.nl.leaseweb.net
* updates: ftp.iitm.ac.in
Available Packages
Name : firefox
Arch : i386
Version : 10.0.6
Release : 1.el5.centos
Size : 20 M
Repo : updates
Summary : Mozilla Firefox Web browser
URL : http://www.mozilla.org/projects/firefox/
License : MPLv1.1 or GPLv2+ or LGPLv2+
Description: Mozilla Firefox is an open-source web browser, designed for standards
: compliance, performance and portability.
7. Elenca tutti i pacchetti disponibili utilizzando YUM
Per elencare tutti i pacchetti disponibili nel database Yum, utilizzare il comando seguente:
# yum list | less
8. Elenca tutti i pacchetti installati utilizzando YUM
Per elencare tutti i pacchetti installati su un sistema, basta emettere il comando sottoindicato, verranno visualizzati tutti i pacchetti installati.
# yum list installed | less
9. Yum provides
La funzione Yum provides viene utilizzato per trovare il pacchetto a cui appartiene un file specifico. Ad esempio, se si desidera conoscere il nome del pacchetto con /etc/httpd/conf/httpd.conf.
# yum provides /etc/httpd/conf/httpd.conf
# yum provides /etc/httpd/conf/httpd.conf
Loaded plugins: fastestmirror
httpd-2.2.3-63.el5.centos.i386 : Apache HTTP Server
Repo : base
Matched from:
Filename : /etc/httpd/conf/httpd.conf
httpd-2.2.3-63.el5.centos.1.i386 : Apache HTTP Server
Repo : updates
Matched from:
Filename : /etc/httpd/conf/httpd.conf
httpd-2.2.3-65.el5.centos.i386 : Apache HTTP Server
Repo : updates
Matched from:
Filename : /etc/httpd/conf/httpd.conf
httpd-2.2.3-53.el5.centos.1.i386 : Apache HTTP Server
Repo : installed
Matched from:
Other : Provides-match: /etc/httpd/conf/httpd.conf
10. Verificare la disponibilità di aggiornamenti utilizzando Yum
Per individuare il numero di pacchetti installati nel sistema in cui sono disponibili aggiornamenti, verificare di utilizzare il comando seguente.
# yum check-update
11. Aggiorna il sistema utilizzando Yum
Per mantenere aggiornato il sistema con tutti gli aggiornamenti dei pacchetti binari e di sicurezza, eseguire il comando seguente. Installerà tutte le patch più recenti e gli aggiornamenti di sicurezza nel sistema.
# yum update
12. Elenca tutti i pacchetti di gruppo disponibili
In Linux, il numero di pacchetti è incluso in un particolare gruppo. Invece di installare singoli pacchetti con yum, è possibile installare un gruppo particolare che installerà tutti i pacchetti correlati che appartengono al gruppo. Ad esempio, per elencare tutti i gruppi disponibili, è possibile rilasciare il comando seguente.
# yum grouplist
Installed Groups:
Administration Tools
DNS Name Server
Dialup Networking Support
Editors
Engineering and Scientific
FTP Server
Graphics
Java Development
Legacy Network Server
Available Groups:
Authoring and Publishing
Base
Beagle
Cluster Storage
Clustering
Development Libraries
Development Tools
Eclipse
Educational Software
KDE (K Desktop Environment)
KDE Software Development
13. Installare pacchetti di gruppo
Per installare un particolare gruppo di pacchetti, viene utilizzato l’opzione groupinstall. Ad esempio, per installare “MySQL Database“, è possibile eseguire il comando riportato di seguito.
# yum groupinstall 'MySQL Database'
Dependencies Resolved
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Updating:
unixODBC i386 2.2.11-10.el5 base 290 k
Installing for dependencies:
unixODBC-libs i386 2.2.11-10.el5 base 551 k
Transaction Summary
=================================================================================================
Install 1 Package(s)
Upgrade 1 Package(s)
Total size: 841 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : unixODBC-libs 1/3
Updating : unixODBC 2/3
Cleanup : unixODBC 3/3
Dependency Installed:
unixODBC-libs.i386 0:2.2.11-10.el5
Updated:
unixODBC.i386 0:2.2.11-10.el5
Complete!
14. Aggiornare un pacchetti di gruppo
Per aggiornare tutti i pacchetti di gruppi installati esistenti, è necessario eseguire il comando seguente, come illustrato di seguito.
# yum groupupdate 'DNS Name Server'
Dependencies Resolved
================================================================================================================
Package Arch Version Repository Size
================================================================================================================
Updating:
bind i386 30:9.3.6-20.P1.el5_8.2 updates 981 k
bind-chroot i386 30:9.3.6-20.P1.el5_8.2 updates 47 k
Updating for dependencies:
bind-libs i386 30:9.3.6-20.P1.el5_8.2 updates 864 k
bind-utils i386 30:9.3.6-20.P1.el5_8.2 updates 174 k
Transaction Summary
================================================================================================================
Install 0 Package(s)
Upgrade 4 Package(s)
Total size: 2.0 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : bind-libs 1/8
Updating : bind 2/8
Updating : bind-chroot 3/8
Updating : bind-utils 4/8
Cleanup : bind 5/8
Cleanup : bind-chroot 6/8
Cleanup : bind-utils 7/8
Cleanup : bind-libs 8/8
Updated:
bind.i386 30:9.3.6-20.P1.el5_8.2 bind-chroot.i386 30:9.3.6-20.P1.el5_8.2
Dependency Updated:
bind-libs.i386 30:9.3.6-20.P1.el5_8.2 bind-utils.i386 30:9.3.6-20.P1.el5_8.2
Complete!
15. Rimuovere pacchetti di gruppo
Per eliminare o rimuovere qualsiasi gruppo installato esistente dal sistema, è necessario utilizzare il comando seguente.
# yum groupremove 'DNS Name Server'
Dependencies Resolved
===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Removing:
bind i386 30:9.3.6-20.P1.el5_8.2 installed 2.1 M
bind-chroot i386 30:9.3.6-20.P1.el5_8.2 installed 0.0
Transaction Summary
===========================================================================================================
Remove 2 Package(s)
Reinstall 0 Package(s)
Downgrade 0 Package(s)
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : bind 1/2
warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave
Erasing : bind-chroot 2/2
Removed:
bind.i386 30:9.3.6-20.P1.el5_8.2 bind-chroot.i386 30:9.3.6-20.P1.el5_8.2
Complete!
16. Elencare i repository Yum abilitati
Per elencare tutti i repository Yum abilitati nel sistema, utilizzare l’opzione seguente.
# yum repolist
repo id repo name status
base CentOS-5 - Base enabled: 2,725
epel Extra Packages for Enterprise Linux 5 - i386 enabled: 5,783
extras CentOS-5 - Extras enabled: 282
mod-pagespeed mod-pagespeed enabled: 1
rpmforge RHEL 5 - RPMforge.net - dag enabled: 11,290
updates CentOS-5 - Updates enabled: 743
repolist: 20,824
16. Elenca tutti i repository Yum abilitati e disabilitati
Il comando seguente visualizza tutti i repository yum abilitati e disabilitati nel sistema.
# yum repolist all
repo id repo name status
C5.0-base CentOS-5.0 - Base disabled
C5.0-centosplus CentOS-5.0 - Plus disabled
C5.0-extras CentOS-5.0 - Extras disabled
base CentOS-5 - Base enabled: 2,725
epel Extra Packages for Enterprise Linux 5 - i386 enabled: 5,783
extras CentOS-5 - Extras enabled: 282
repolist: 20,824
17. Installare un pacchetto da un repository specifico
Per installare un determinato pacchetto da un repository specifico abilitato o disabilitato, è necessario utilizzare l’opzione –enablerepo nel comando yum. Ad esempio, per installare phpmyadmin 3.5.2 pacchetto, basta eseguire il comando.
# yum --enablerepo=epel install phpmyadmin
Dependencies Resolved
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Installing:
phpMyAdmin noarch 3.5.1-1.el6 epel 4.2 M
Transaction Summary
=============================================================================================
Install 1 Package(s)
Total download size: 4.2 M
Installed size: 17 M
Is this ok [y/N]: y
Downloading Packages:
phpMyAdmin-3.5.1-1.el6.noarch.rpm | 4.2 MB 00:25
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : phpMyAdmin-3.5.1-1.el6.noarch 1/1
Verifying : phpMyAdmin-3.5.1-1.el6.noarch 1/1
Installed:
phpMyAdmin.noarch 0:3.5.1-1.el6
Complete!
18. Shell interattiva Yum
L’utilità Yum fornisce una shell personalizzata in cui è possibile eseguire più comandi.
# yum shell
Loaded plugins: fastestmirror
Setting up Yum Shell
> update httpd
Loading mirror speeds from cached hostfile
* base: mirrors.sin3.sg.voxel.net
* epel: ftp.riken.jp
* extras: mirrors.sin3.sg.voxel.net
* updates: mirrors.sin3.sg.voxel.net
Setting up Update Process
>
19. Clean Yum Cache
Per impostazione predefinita yum mantiene tutti i dati del pacchetto abilitati per il repository in /var/cache/yum/ con ogni sotto-directory, per pulire tutti i file memorizzati nella cache dal repository abilitato, è necessario eseguire regolarmente il seguente comando per ripulire tutta la cache e assicurarsi che non vi sia nulla di necessario. (Non voglio dare l’output del comando sottostante, perché mi piace mantenere i dati memorizzati nella cache così come sono).
# yum clean all
20. Visualizza la storia di Yum
Per visualizzare tutte le transazioni passate del comando yum, è necessario utilizzare il comando seguente.
# yum history
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
10 | root | 2012-08-11 15:19 | Install | 3
9 | root | 2012-08-11 15:11 | Install | 1
8 | root | 2012-08-11 15:10 | Erase | 1 EE
7 | root | 2012-08-10 17:44 | Install | 1
6 | root | 2012-08-10 12:19 | Install | 2
5 | root | 2012-08-10 12:14 | Install | 3
4 | root | 2012-08-10 12:12 | I, U | 13 E<
3 | root | 2012-08-09 13:01 | Install | 1 >
2 | root | 2012-08-08 20:13 | I, U | 292 EE
1 | System | 2012-08-08 17:15 | Install | 560
history list
Ho cercato di coprire tutte le basi dei i comandi yum con i loro esempi. Se ci sono domande o quesiti, scrivi nella casella dei commenti.
Scarica l’ applicazione per restare sempre aggiornato
Pingback: Installare VirtualBox 6.1 su Linux * IRCwebNet - IRC and Linux World