rpm包一般都有默认的安装路径,如何你要更改默认路径,有没有办法呢?当然有。我们来看下面的例子。
比如在安装JDK (Java Development Kit)或JRE (Java Runtime Environment)时,这个 package文件的默认安装路径是/usr/java。如果你要安装在其它路径下,例如要放到/home/java目录下,该如何做呢?
一、首先查看rpm包的详细信息
[root@ ~]# 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 :
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.
这个JDK是默认要装在/usr/java 下的。
下面我们这样来设置参数,就可以把JDK装在你指定的目录下。
[root@linuxidc ~]# 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
参数释义:
badreloc是强制把文件安装到你想要的地方。
relocate就是只把应该装到oldpath下的文件安装到newpath,实现将一部分文件安装到其它的路径,而不是把所有的这个包的文件都替换。
但是无论是prefix还是relocate都不见得可以真正可以用,因为有的包或者文件不允许装到其他路径,比如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 :
Summary : The Oracle Automatic Storage Management support programs.
Description :
Tools to manage the Oracle Automatic Storage Management library driver
not relocatable不能重定位,是无法修改安装目录的,只有去掉 --prefix参数了。
[root@linuxidc ~]# java -version
-bash: /usr/bin/java: No such file or directory
这时没有显示JAVA版本号,是因为环境变量还没修改。
下面修改一下JAVA的环境变量
[root@linuxidc 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@linuxidc jdk1.6.0_43]# source /etc/profile
使环境变量生效。
再查看,就有JAVA版本号显示了。
[root@linuxidc 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)
补充一下:
在安装JDK时,需要查看一下原系统是否有其他的JAVA版本号,如果跟你要装的不一致,请卸载后再装。
[root@linuxidc ~]# 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)
进行查找
[root@linuxidc ~]# 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
强制卸载
[root@linuxidc ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
[root@linuxidc ~]# 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@linuxidc ~]# rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
再检查,发现已卸载干净。
[root@linuxidc ~]# java -version
-bash: /usr/bin/java: No such file or directory
RPM包创建入门
如何在Linux中创建RPM包?
制作自己的rpm包
Linux 下rpm安装后的目录结构和一些配置
rpm与yum的综合性介绍与示例演示
Redhat Linux---rpm 命令详解
使用FPM轻松制作RPM包
本文永久更新链接地址: