JAVA_HOME和PATH环境变量不在UBUNTU中工作。

时间:2022-09-29 23:22:15

I have downloaded jdk-7u9-linux-i586.rpm from oracle. Then I installed it in my Ubuntu 12.04 LTS. Then I set the environment path as :

我已经下载了jdk-7u9-linux-i586。rpm从oracle。然后我在Ubuntu 12.04 LTS中安装了它。然后我设置环境路径为:

 export JAVA_HOME=/usr/java/<the jdk directory I cant recall now>
 export PATH={$PATH}:{$JAVA_HOME}/bin

Then I checked by echo $PATH and echo $JAVA_HOME. Now it is showing correct paths.

然后我通过echo $PATH和echo $JAVA_HOME检查。现在它显示了正确的路径。

BUT THE PROBLEM IS : IF I TRY java IN THE CONSOLE IT IS SHOWING UNRECOGNIZED COMMAND ERROR.

但问题是:如果我在控制台尝试java,它会显示未识别的命令错误。

Please help me.

请帮助我。

3 个解决方案

#1


2  

You changed your PATH, but did you re-source and refresh your PATH cache ? (see here for more details, and check section 3)

你改变了你的路径,但是你重新获取并刷新了你的路径缓存吗?(详情请参看第3节)

e.g.

如。

$ vi ~/.profile
$ . ~/.profile
$ echo $PATH # is this right ?

and a possible hash

和可能的哈希

$ hash

#2


1  

If you simply call export in a shell, you will set the variables exactly for this one environment. If you want those variables to be there for all shell environments, add them to your ~/.bashrc or your ~/.profile files.

如果您简单地调用shell中的导出,那么您将为这个环境设置精确的变量。如果您希望这些变量在所有shell环境中都存在,请将它们添加到您的~/中。bashrc或你(~ /。概要文件。

EDIT: I think, using a RedHat-specific packages (.rpm) on Ubuntu may be a cause of your issue - this is a rather wild guess though. You could either remove your current installation and try a different package, or better yet, install java using your regular packgage manager:

编辑:我认为,在Ubuntu上使用一个红帽子的软件包(.rpm)可能是您的问题的原因——这是一个相当疯狂的猜测。您可以删除当前安装并尝试不同的包,或者更好的是,使用常规的packgage管理器安装java:

sudo add-apt-repository ppa:webupd8team/java 
apt-get update 
sudo apt-get install oracle-java7-installer

#3


0  

Finally I got it.
It was all my mistake. I have set the PATH variable in the /etc/environment file and it was set wrongly. I set it upto jdk folder and not /bin after that.

最后,我明白了。这全是我的错。我在/etc/environment文件中设置了PATH变量,并且设置错误。我将它设置为jdk文件夹而不是/bin之后。

After changing it to bin, I logged out and logged in again.
Now it is working fine.

在将它更改为bin之后,我退出并再次登录。现在它运行良好。

Sorry guys for wasting your time and efforts.

对不起,伙计们,浪费了你们的时间和精力。

#1


2  

You changed your PATH, but did you re-source and refresh your PATH cache ? (see here for more details, and check section 3)

你改变了你的路径,但是你重新获取并刷新了你的路径缓存吗?(详情请参看第3节)

e.g.

如。

$ vi ~/.profile
$ . ~/.profile
$ echo $PATH # is this right ?

and a possible hash

和可能的哈希

$ hash

#2


1  

If you simply call export in a shell, you will set the variables exactly for this one environment. If you want those variables to be there for all shell environments, add them to your ~/.bashrc or your ~/.profile files.

如果您简单地调用shell中的导出,那么您将为这个环境设置精确的变量。如果您希望这些变量在所有shell环境中都存在,请将它们添加到您的~/中。bashrc或你(~ /。概要文件。

EDIT: I think, using a RedHat-specific packages (.rpm) on Ubuntu may be a cause of your issue - this is a rather wild guess though. You could either remove your current installation and try a different package, or better yet, install java using your regular packgage manager:

编辑:我认为,在Ubuntu上使用一个红帽子的软件包(.rpm)可能是您的问题的原因——这是一个相当疯狂的猜测。您可以删除当前安装并尝试不同的包,或者更好的是,使用常规的packgage管理器安装java:

sudo add-apt-repository ppa:webupd8team/java 
apt-get update 
sudo apt-get install oracle-java7-installer

#3


0  

Finally I got it.
It was all my mistake. I have set the PATH variable in the /etc/environment file and it was set wrongly. I set it upto jdk folder and not /bin after that.

最后,我明白了。这全是我的错。我在/etc/environment文件中设置了PATH变量,并且设置错误。我将它设置为jdk文件夹而不是/bin之后。

After changing it to bin, I logged out and logged in again.
Now it is working fine.

在将它更改为bin之后,我退出并再次登录。现在它运行良好。

Sorry guys for wasting your time and efforts.

对不起,伙计们,浪费了你们的时间和精力。