天天看點

從零開始--(1)Linux虛拟機下使用yum安裝gcc

裝了Linux虛拟機rhel-server-6.4 版本後,在網上看到利用 yum -y install gcc安裝gcc的教程,遇到的各種問題,因為是小白,一步一步詳解如下:

1.首先切換root賬号:

從零開始--(1)Linux虛拟機下使用yum安裝gcc

 輸入su後輸入密碼, 切換到root $ -> #

從零開始--(1)Linux虛拟機下使用yum安裝gcc

2. 按照網上教程輸入, yum -y install gcc ,并沒有成功,傳回Error。網上搜了一下需要先删除掉redhat自帶的yum包。

[[email protected] ~]# rpm -qa|grep yum|xargs rpm -e --nodeps(不檢查依賴,直接删除rpm包)

再用

[[email protected] ~]# rpm -qa |grep yum

[[email protected] ~]# 

從零開始--(1)Linux虛拟機下使用yum安裝gcc

3.下載下傳yum包

#wget  url/yum-3.2.27-14.el6.centos.noarch.rpm

#wget url/yum-metadata-parser-1.1.2-14.1.el6.x86_64.rpm

#wget url/yum-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm

#wget url/python-iniparse-0.3.1-2.1.el6.noarch.rpm

注:網上的url絕大多數都是不準的, 自己根據系統位數将url替換下面的路徑:

32位: http://mirrors.163.com/centos/6/os/i386/Packages/

64位:http://tel.mirrors.163.com/centos/6/os/x86_64/Packages/

可以打開上面的路徑自己查找。

4. 安裝

注意:單個的安裝包可能會依賴其它包(例如yum和yum-fastestmirror會互相依賴),是以我們可以把所有這些包放在一起,用一行指令将它們同時安裝即可:

#rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm

# rpm -ivh yum-metadata-parser-1.1.2-14.el6.i686.rpm 

yum-3.2.27-14.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm

5. yum配置

# cd /etc/yum.repos.d/

# wget  http://mirrors.163.com/.help/CentOS6-Base-163.repo

# vi CentOS6-Base-163.repo

修改如下幾處:

# CentOS-Base.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client.  You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

[base]

name=CentOS-6 - Base - 163.com

baseurl=http://mirrors.163.com/centos/6/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates

[updates]

name=CentOS-6 - Updates - 163.com

baseurl=http://mirrors.163.com/centos/6/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful

[extras]

name=CentOS-6 - Extras - 163.com

baseurl=http://mirrors.163.com/centos/6/extras/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-6 - Plus - 163.com

baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus

gpgcheck=1

enabled=0

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users

[contrib]

name=CentOS-6 - Contrib - 163.com

baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib

gpgcheck=1

enabled=0

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

儲存退出 (按esc之後, wq )

6.清除原有緩存

# yum clean all

PS: 本人在此處還是會有報錯, 進入etc/yum.repos.d/後發現還有多餘的幾個.repo檔案,是以發狠 rm -rf 

删了幹淨,重新來過,終于搞定!

重建緩存,以提高搜尋安裝軟體的速度

# yum makecache

更新系統

# yum update

PS:

檢視Linux是32還是64: 

1.uname -a

例如我的機子輸入指令後輸出:

Linux zou-acertox42 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:05:41 UTC 2011 i686 i686 i386 GNU/Linux

如果是64位的則可能輸出:

Linux web1 2.6.9-22.ELsmp #1 SMP Mon Sep 19 18:00:54 EDT 2005 x86_64 x86_64 x86_64 GNU/Linux

2. #getconf LONG_BIT 

繼續閱讀