Ubuntu terminal sudo java prompts "command not found" SOLUTION

Source: Internet
Author: User

I want to start a java program sudo java-jar xxx. jar in ubuntu 12.04, but the result shows sudo: java: command not found.

When running java programs with sudo in Ubuntu, note that the user directory is/root instead of/home/YournameAnd so on. If you do not notice this, you may encounter a situation where a java-related component places some configurations in/home/by default/YournameBut the java program you started with sudo went to/root to find this file, and the result was not found. If the relevant module does not report an error or a high-profile error, you can hardly find out where the error is.

This is generally because your root user does not configure the java path. The sudo environment variables are different from the normal user's environment variables. When sudo environment variables are integrated with the root user, the PATH variable of sudo is generally:/sbin:/usr/sbin:/bin:/usr/bin.

You can try sudo 'which Java'-jar XX. jar.

In addition, another jdk configuration method can solve this problem. The previously modified/etc/profile configuration was later changed to/etc/environment (note that in/etc/environment, do not export PATH = ..., otherwise, it will be stuck on the login interface ). After/etc/environment is configured, source/etc/environment can be executed in sudo java.

 

Note:

(1)/etc/environment is used to set the entire system environment, while/etc/profile is used to set the environment for all users. The former has nothing to do with the login user, and the latter has to do with the login user. The execution of system applications may be unrelated to the user environment, but related to the system environment. Therefore, when you log on, you will see the prompt information, if the display format of date and time information is related to the LANG of the system environment, the default LANG = en_US, if the system environment LANG-zh_CN, the prompt information is Chinese, otherwise it is English.

(2) When logging on to the system, the shell should read/etc/profile->/etc/environment-> $ HOME/. profile-> $ HOME/. env.

(3) If the same variable has different values in the user environment (/etc/profile) and system environment (/etc/environment), the user environment shall prevail.

 

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.