简体   繁体   中英

Raspberry pi update the java path

I installed the last image "RASPBIAN Debian Wheezy" on my Pi and it contains java 8 After that I installed java 7: and I want to modify the java path from java 8 to java 7 So I updated my environment variables to:

export JAVA_HOME=/usr/lib/jvm/jdk-7-oracle-armhf/bin/java
export PATH=$PATH:/usr/lib/jvm/jdk-7-oracle-armhf/bin

I added them to my ~/.bashrc

but still when I execute java -version I got the java 8, even after reboot:

java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

and when I display my envirnment variables, I got the java 7!:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/jdk-7-oracle-armhf/bin

pi@raspberrypi /usr/bin $ echo $JAVA_HOME
/usr/lib/jvm/jdk-7-oracle-armhf/bin/java

How can I update the path so that the command "java -version" gave me the java 7?

You need to use update-alternatives

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-7-oracle-armhf/bin/java" 1  
sudo update-alternatives --set java /usr/lib/jvm/jdk-7-oracle-armhf/bin/java

If still having problems check here http://www.element14.com/community/docs/DOC-54112/l/java-on-the-raspberry-pi

Simply, your PATH is in the wrong order. The conventional way would be:

export JAVA_HOME=/usr/lib/jvm/jdk-7-oracle-armhf
export PATH=$JAVA_HOME/bin:$PATH

Note that I prepended your new java. Since PATH is searched in order, it would still find the old java first, otherwise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM