【问题标题】:Unable to set the PATH variable for jdk无法为 jdk 设置 PATH 变量
【发布时间】:2012-05-03 19:42:40
【问题描述】:

我已经在archlinux kde 中安装了sun-java,方法是先构建包然后安装它。这是在我的机器中设置环境变量的方式: 文件:/etc/profile # /etc/profile

#Set our umask
umask 022

# Set our default path
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
export PATH

# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
    for profile in /etc/profile.d/*.sh; do
        test -r "$profile" && . "$profile"
done
unset profile
fi

# Source global bash config
if test "$PS1" && test "$BASH" && test -r /etc/bash.bashrc; then
. /etc/bash.bashrc
fi

# Termcap is outdated, old, and crusty, kill it.
unset TERMCAP

# Man is much better than us at figuring this out
unset MANPATH

和文件:/etc/profile.d/jdk.sh

export J2SDKDIR=/opt/java
export PATH=$PATH:/opt/java/bin:/opt/java/db/bin
export JAVA_HOME=/opt/java
export DERBY_HOME=/opt/java/db

我从中了解到的是,jdk 路径应该在路径环境变量中设置,但不是。但是属性 $JAVA_HOME 设置正确。为什么我会遇到这个问题?

【问题讨论】:

  • 在您的 PATH= /opt/java 中应该先运行,否则安装在 /usr/bin 中的 java 将首先运行。
  • @geeky_sh echo $PATH 的输出是什么?
  • echo $path /home/absolute/.rvm/gems/ruby1.9.3p0/bin:/home/absolute/.rvm/gems/ruby1.9.3p0@global/bin:/home/绝对/.rvm/rubies/ruby1.9.3p0/bin:/home/absolute/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin :/sbin:/usr/bin/core_perl:/home/absolute/.rvm/bin
  • @tigran 在 /usr/bin 中找不到名为 java 的文件
  • 等等,是echo $PATH 还是你上面写的echo $path。 Linux/Unix/bash/ksh/etc_shell 中的变量区分大小写。确保您正在查看正确的变量。请为您使用的操作系统环境添加标签,Linux、Unix、WindowsX。此外,在回答有关您的环境、设置、输入、预期输出和错误消息的问题时,最好编辑您的原始问题。所以,我建议您编辑您的问题以包含echo $PATH 的输出。祝你好运。

标签: bash java-7 bash4


【解决方案1】:

/etc/profile 和 /etc/profile.d 仅针对 login shells 进行处理,因此除非您在安装了 java 的机器上执行 ssh,否则您不会获得这些变量。

要将它们本地(例如,当您在工作站上打开 xterm 时)将它们放在文件 /etc/bash.bashrc 中。

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    实际上,这是我的一个愚蠢的错误。我正在使用 zsh 外壳。所以我被要求输入:

        export PATH=$PATH:$JAVA_HOME/bin 
    

    在 .zshrc 文件而不是 .bashrc 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-25
      • 2021-02-12
      • 1970-01-01
      • 2017-02-18
      • 2017-03-06
      • 2013-07-27
      • 1970-01-01
      • 2016-04-12
      相关资源
      最近更新 更多