如何在Linux中为所有用户设置JAVA_HOME [英] How to set JAVA_HOME in Linux for all users

查看:596
本文介绍了如何在Linux中为所有用户设置JAVA_HOME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Linux系统的新手,似乎有太多的Java文件夹。

I am new to Linux system and there seem to be too many Java folders.

java -version给了我:

java -version gives me:


  • java version1.7.0_55

  • OpenJDK运行时环境(rhel-2.4.7.1.el6_5-x86_64 u55-b13)

  • OpenJDK 64位服务器VM(内部版本24.51-b03) ,混合模式)

当我尝试构建Maven项目时,我收到错误:

When I am trying to build a Maven project , I am getting error:

Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/java/jdk1.7.0_05/bin/java

可能请告诉我哪些文件需要修改为root用户以及非root用户以及java的确切位置?

Could you please tell me which files I need to modify for root as well as not-root user and where exactly is java located?

推荐答案


  1. 查找/usr/lib/jvm/java-1.xx-openjdk

  2. vim / etc / profile

如果以非特权用户身份登录,则前置sudo,即。 sudo vim

Prepend sudo if logged in as not-privileged user, ie. sudo vim

添加:

export JAVA_HOME="path that you found"

export PATH=$JAVA_HOME/bin:$PATH


  • 退出并再次登录,重新启动或使用 source / etc / profile 立即在当前shell中应用更改

  • logout and login again, reboot, or use source /etc/profile to apply changes immediately in your current shell
  • 这篇关于如何在Linux中为所有用户设置JAVA_HOME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆