linux下安装openjdk1.8
使用yum查找jdk: yum search java|grep jdk
[root@localhost network-scripts]# yum search java|grep jdk One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable <repoid> or subscription-manager repos --disable=<repoid> 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: base/7/x86_64
使用yum时遇到上图所示问题,解决办法(修改dns配置):
vi /etc/resolv.conf
在文件/etc/resolv.conf最后写入:nameserver 114.114.114.114(这是国内的dns服务器系统,还是比较好用的。谷歌的可以使用8.8.8.8)
之后再使用yum查找jdk: yum search java|grep jdk
执行安装命令:yum install java-1.8.0-openjdk
如下图 输入y即可:
安装成功后,默认安装路径在/usr/lib/jvm/下边
验证java是否安装成功 查看java版本:java -version
安装开发环境:yum install java-1.8.0-openjdk-devel.x86_64
验证java是否安装成功 执行:javac
设置环境变量
修改/etc/profile文件:vi /etc/profile
# set java env JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64 JRE_HOME=$JAVA_HOME/jre CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin export JAVA_HOME JRE_HOME CLASS_PATH PATH
使环境变量生效执行:source /etc/profile
安装完成!!!