How to set up the Java environment in Linux?

I am using Fedora 20. I installed the rpm from Oracle for the Oracle JDK. How to set up the environment so that the Java environment is Oracle JDK instead of the OpenJDK?

The Oracle JDK is install to /usr/java/ directory. On my Fedora 20, it looks like this:

$ ls /usr/java -l
total 4
lrwxrwxrwx. 1 root root   16 Oct  7  2013 default -> /usr/java/latest
drwxr-xr-x  8 root root 4096 Apr 18 11:21 jdk1.8.0_05
lrwxrwxrwx  1 root root   21 Apr 18 11:21 latest -> /usr/java/jdk1.8.0_05

I put these 3 lines into my ~/.bashrc (I am using bash) to set up the Java environment:

export JAVA_HOME=/usr/java/default/
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

JAVA_HOME and CLASSPATH are for Java. I use /usr/java/default/ because this way I will not need to update my ~/.bashrc next time the JDK is upgraded. The last line puts the Java binary directory into the PATH so that the default of invoking of Java software such as java and javac will be the one from the Oracle JDK.

And this is the java version:

$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

$ javac -version
javac 1.8.0_05

Similar Posts

  • Java与C++在语言方面上的不同

    1,Java抛弃了头文件、预处理机制、goto语句和多维数组。 2,Java不支持指针。 3,Java抛弃了联合体和结构体。 4,Java不支持独立函数。所有函数必须在类中声明。 5,Java不支持多重继承,可以使用接口模拟多重继承。 6,Java不支持运算符重载。 7,Java中布尔型不再用整数来代替。 8,Java中主函数必须有一个字符串类型的参数。 Java抛弃的C++中的这些机制和结构多数都是“危险”的,减少了语言的复杂性,增强了安全性,虽然在一定程度上减少了其灵活性。 Read more: Java Calling Native Functions in .DLL on Windows OCaml Learning Materials Vim Indenting C/C++ Code MFC程序使用系统风格界面 Linux UDP Programming Tutorial Checking Whether a String Starts with Another String in C++ GCC May “Save” You Some Recursive Functions Calls: an Analysis of a Function Call…

Leave a Reply

Your email address will not be published. Required fields are marked *