Ubuntu sets environment variables and takes effect immediately

Source: Internet
Author: User

Ubuntu Linux systems contain two types of environment variables: System environment variables and user environment variables. The system environment variable is valid for all system users, and the user environment variable is only valid for the current user.

modifying user environment variables

User environment variables are typically stored in the following file:

    • ~/.profile

    • ~/.bash_profile or ~./bash_login

    • ~/.bashrc

The above files are not recommended for use in previous versions of Ubuntu 10.0.

System Environment variables

The system environment variables are generally stored in the following file:

    • /etc/environment

    • /etc/profile

    • /etc/bash.bashrc

/etc/profile and/ETC/BASH.BASHRC are not recommended for use in Ubuntu version 10.0.

Adding environment variables

If you want to add a path to $path, you can do the following (modify/etc/profile):

1 sudo nano /etc/profile

Add in:

123456 JAVA_HOME=/usr/jdk1.6.0_25exportJAVA_HOMEPATH=$PATH:$JAVA_HOME/binexport PATHCLASSPATH=.:$JAVA_HOME/libexportCLASSPATH

You can add the specified number of paths yourself, separated by colons. When the environment variable is changed, it takes effect the next time the user logs on, and if you want to take effect immediately, you can execute the following statement:

1 $source/etc/profile

It is important to note that it is best not to put the current path "./" in path, which may be subject to unexpected attacks.

Other files are modified in a similar manner, and it is important to note that/etc/environment does not need to use export to set environment variables that other profile files require.

For more detailed instructions, refer to here.

Of course, if you want to use the text Editing tool to modify environment variables, you can use the root permission to log in, directly with a text editor open modify Save

can also be normal user permissions to copy files to the desktop and other changes with the root permission to cover back

1234567891011121314151617181920212223242526272829303132333435 # /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).     if [ -d /etc/profile.d ]; then   for i in /etc/profile.d/*.sh; do     if [ -r $i ]; then       . $i     fi   done     JAVA_HOME=/usr/hadoop/jdk1.6.0_25 export JAVA_HOME PATH=$PATH:$JAVA_HOME/bin export PATH CLASSPATH=.:$JAVA_HOME/lib export CLASSPATH       unset i fi     if [ "$PS1" ]; then   if [ "$BASH" ]; then     # The file bash.bashrc already sets the default PS1.     # PS1=‘\h:\w\$ ‘     if [ -f /etc/bash.bashrc ]; then       . /etc/bash.bashrc     fi   else     if [ "`id -u`" -eq 0 ]; then       PS1=‘# ‘     else       PS1=‘$ ‘     fi   fi fi

http://snowfigure.diandian.com/post/2012-09-23/40038540721

Ubuntu sets environment variables and takes effect immediately

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.