本篇内容介绍了“Ubuntu下怎么安装JDK 1.8”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
Ubuntu14.04 LTS下安装JDK 1.8
先到Oracle官网的下载中心下载JDK8的tar包到本地。
创建应用程序主目录
linuxidc@ubuntu:/usr/lib$ sudo mkdir jvm
解压下载的tar包到应用程序主目录下
linuxidc@ubuntu:~/Downloads$ sudo tar zxf jdk-8u65-linux-x64.tar.gz -C /usr/lib/jvm
重命名下文件夹
linuxidc@ubuntu:/usr/lib/jvm$ sudo mv jdk1.8.0_65 java
安装vim(因为UBuntu默认情况下不安装vim命令,需要用apt-get命令安装)
linuxidc@ubuntu:/usr/lib/jvm/java$sudoapt-getinstallvimReadingpackagelists...DoneBuildingdependencytreeReadingstateinformation...DoneThefollowingextrapackageswillbeinstalled:vim-runtimeSuggestedpackages:ctagsvim-docvim-scriptsThefollowingNEWpackageswillbeinstalled:vimvim-runtime0upgraded,2newlyinstalled,0toremoveand6notupgraded.Needtoget5,844kBofarchives.Afterthisoperation,28.0MBofadditionaldiskspacewillbeused.Doyouwanttocontinue?[Y/n]yGet:1http://us.archive.ubuntu.com/ubuntu/trusty/mainvim-runtimeall2:7.4.052-1ubuntu3[4,888kB]Get:2http://us.archive.ubuntu.com/ubuntu/trusty/mainvimamd642:7.4.052-1ubuntu3[956kB]Fetched5,844kBin18min52s(5,159B/s)
配置环境变量,vim ~/.bashrc文件
linuxidc@ubuntu:/usr/lib/jvm/java$ sudo vim ~/.bashrc
添加下面的内容到文件尾部
exportJAVA_HOME=/usr/lib/jvm/javaexportJRE_HOME=${JAVA_HOME}/jreexportCLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libexportPATH=${JAVA_HOME}/bin:$PATH
如果你的Ubuntu上已经安装了其他版本的JDK,你可以通过update-alternatives命令来设定比如命令Java的默认命令路径。然后就是编译下让update-alternatives配置生效。
linuxidc@ubuntu:/usr/lib/jvm/java$sudoupdate-alternatives--install/usr/bin/javajava/usr/lib/jvm/java/bin/java300update-alternatives:using/usr/lib/jvm/java/bin/javatoprovide/usr/bin/java(java)inautomodelinuxidc@ubuntu:/usr/lib/jvm/java$sudoupdate-alternatives--install/usr/bin/javacjavac/usr/lib/jvm/java/bin/javac300update-alternatives:using/usr/lib/jvm/java/bin/javactoprovide/usr/bin/javac(javac)inautomodelinuxidc@ubuntu:/usr/lib/jvm/java$sudoupdate-alternatives--install/usr/bin/jarjar/usr/lib/jvm/java/bin/jar300update-alternatives:using/usr/lib/jvm/java/bin/jartoprovide/usr/bin/jar(jar)inautomodelinuxidc@ubuntu:/usr/lib/jvm/java$sudoupdate-alternatives--install/usr/bin/javahjavah/usr/lib/jvm/java/bin/javah300update-alternatives:using/usr/lib/jvm/java/bin/javahtoprovide/usr/bin/javah(javah)inautomodelinuxidc@ubuntu:/usr/lib/jvm/java$sudoupdate-alternatives--install/usr/bin/javapjavap/usr/lib/jvm/java/bin/javap300update-alternatives:using/usr/lib/jvm/java/bin/javaptoprovide/usr/bin/javap(javap)inautomodelinuxidc@ubuntu:/usr/lib/jvm/java$sudoupdate-alternatives--configjavaThereisonlyonealternativeinlinkgroupjava(providing/usr/bin/java):/usr/lib/jvm/java/bin/javaNothingtoconfigure.
最后检查是否安装成功
linuxidc@ubuntu:/usr/lib/jvm/java$ java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
linuxidc@ubuntu:/usr/lib/jvm/java$
“Ubuntu下怎么安装JDK 1.8”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!