rpm包一般都有默認(rèn)的安裝路徑,如何你要更改默認(rèn)路徑,有沒(méi)有辦法呢?當(dāng)然有。我們來(lái)看下面的例子。
成都創(chuàng)新互聯(lián)公司長(zhǎng)期為成百上千家客戶(hù)提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為謝家集企業(yè)提供專(zhuān)業(yè)的成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì),謝家集網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。
比如在安裝JDK (Java Development Kit)或JRE (Java Runtime Environment)時(shí),這個(gè)Redhat package文件的默認(rèn)安裝路徑是/usr/java。如果你要安裝在其它路徑下,例如要放到/home/java目錄下,該如何做呢?
一、首先查看rpm包的詳細(xì)信息
[root@oracle ~]# rpm -qpi jdk-6u43-linux-amd64.rpm
Name : jdk Relocations: /usr/java
Version : 1.6.0_43 Vendor: Oracle and/or its affiliates.
Release : fcs Build Date: Fri 01 Mar 2013 09:03:27 PM CST
Install Date: (not installed) Build Host: jb6-lin-amd64.sfbay.sun.com
Group : Development/Tools Source RPM: jdk-1.6.0_43-fcs.src.rpm
Size : 127075557 License: Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. Also under other license(s) as shown at the Description field.
Signature : (none)
Packager : Java Software
URL : http://www.oracle.com/technetwork/java/javase/overview/index.html
Summary : Java(TM) Platform Standard Edition Development Kit
Description :
The Java Platform Standard Edition Development Kit (JDK) includes both
the runtime environment (Java virtual machine, the Java platform classes
and supporting files) and development tools (compilers, debuggers,
tool libraries and other tools).
The JDK is a development environment for building applications, applets
and components that can be deployed with the Java Platform Standard
Edition Runtime Environment.
這個(gè)JDK是默認(rèn)要裝在/usr/java 下的。
下面我們這樣來(lái)設(shè)置參數(shù),就可以把JDK裝在你指定的目錄下。
[root@sharesan ~]# rpm -i --badreloc --relocate /usr/java=/home/java jdk-6u43-linux-amd64.rpm
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
ln: creating symbolic link `/usr/java/jdk1.6.0_43': No such file or directory
參數(shù)釋義:
badreloc是強(qiáng)制把文件安裝到你想要的地方。
relocate就是只把應(yīng)該裝到oldpath下的文件安裝到newpath,實(shí)現(xiàn)將一部分文件安裝到其它的路徑,而不是把所有的這個(gè)包的文件都替換。
但是無(wú)論是prefix還是relocate都不見(jiàn)得可以真正可以用,因?yàn)橛械陌蛘呶募辉试S裝到其他路徑,比如oracleasm-support-2.1.8-1.el6.x86_64.rpm
[root@oracle ~]# rpm -qpi oracleasm-support-2.1.8-1.el6.x86_64.rpm
warning: oracleasm-support-2.1.8-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Name : oracleasm-support Relocations: (not relocatable)
Version : 2.1.8 Vendor: Oracle Corporation
Release : 1.el6 Build Date: Sat 09 Feb 2013 06:46:49 AM CST
Install Date: (not installed) Build Host: ca-build44.us.oracle.com
Group : System Environment/Kernel Source RPM: oracleasm-support-2.1.8-1.el6.src.rpm
Size : 221696 License: GPL
Signature : RSA/8, Sat 09 Feb 2013 06:50:30 AM CST, Key ID 72f97b74ec551f03
Packager : Joel Becker
URL : http://oss.oracle.com/projects/oracleasm/
Summary : The Oracle Automatic Storage Management support programs.
Description :
Tools to manage the Oracle Automatic Storage Management library driver
not relocatable不能重定位,是無(wú)法修改安裝目錄的,只有去掉 --prefix參數(shù)了。
[root@sharesan ~]# java -version
-bash: /usr/bin/java: No such file or directory
這時(shí)沒(méi)有顯示JAVA版本號(hào),是因?yàn)榄h(huán)境變量還沒(méi)修改。
下面修改一下JAVA的環(huán)境變量
[root@sharesan jdk1.6.0_43]# vi /etc/profile
JAVA_HOME=/home/java/jdk1.6.0_43
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
"/etc/profile" 85L, 1961C written
[root@sharesan jdk1.6.0_43]# source /etc/profile
使環(huán)境變量生效。
再查看,就有JAVA版本號(hào)顯示了。
[root@sharesan jdk1.6.0_43]# java -version
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)
補(bǔ)充一下:
在安裝JDK時(shí),需要查看一下原系統(tǒng)是否有其他的JAVA版本號(hào),如果跟你要裝的不一致,請(qǐng)卸載后再裝。
[root@sharesan ~]# java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
進(jìn)行查找
[root@sharesan ~]# rpm -aq |grep java
java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
tzdata-java-2013g-1.el6.noarch
java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
強(qiáng)制卸載
[root@sharesan ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
[root@sharesan ~]# rpm -aq |grep java
tzdata-java-2013g-1.el6.noarch
java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
[root@sharesan ~]# rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
再檢查,發(fā)現(xiàn)已卸載干凈。
[root@sharesan ~]# java -version
-bash: /usr/bin/java: No such file or directory