Some problems with configuring Java environment variables in Ubuntu

Source: Internet
Author: User

Recently, because of the re-installation of the system, it is necessary to reconfigure the Java environment variables, originally intended to be configured in/etc/environment, but configured to reboot after the discovery of the GUI, ctrl+alt+f2~6 can enter the command line, but in the command line to try to use sudo Su switch to root user will fail again, after checking some of the data found that because the environment do not use export to match environment variables, which will lead to the problem of login failure, and because the Java path when we add some path in front of the original path, resulting in the subsequent/ Directories such as bin and/usr/bin cannot be found, so the sudo command cannot be found.

The solution is as follows:

Ctrl+alt+f2~6 enters the command line and then logs in with a normal user, using an absolute path to invoke the sudo command, such as:

/usr/bin/sudo/usr/bin/vi/etc/environment

After opening, the previously added environment variable configuration is deleted, reverting to the original appearance of the system. Then add the configuration of the environment variable at the end of the/etc/profile:

Export java_home=/home/joey/softwares/jdk1.7.0_79
Export path= $JAVA _home/bin: $PATH
Export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

This configures Java as well. Also, here are some notes on what Linux configuration files are called:

(1)/etc/enviroment is the environment variable of the system.

(2)/etc/profile: is the environment variable for all users . When the user logs on for the first time , the file is executed. and collect the shell settings from the configuration file of the/ETC/PROFILE.D directory.

(3)/ETC/BASHRC: Executes this file for each user running the bash shell. When the bash shell is opened, the file is read.

(4) ~/.bash_profile: Each user can use this file to enter the shell information dedicated to their own use, when the user log on, the file is only executed once! By default, he sets some environment variables to execute the user's. bashrc file.

(5) ~/.BASHRC: This file contains bash information dedicated to your bash shell, which is read when you log in and every time you open a new shell.

(6) ~/.bash_logout: Executes the file each time it exits the system (exiting the bash shell). In addition, the variables set in/etc/profile (global) can be applied to any user, while the variables set in ~/.BASHRC, etc. (local) only inherit variables from/etc/profile, they are "parent-child" relationships.

(7) ~/.bash_profile is the interactive, login way into bash run ~/.BASHRC is the interactive non-login way into bash normally the two settings are roughly the same, so the former usually calls the latter.


Some problems with configuring Java environment variables in Ubuntu

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.