How to set up the Ubuntu environment variable PATH and configure backup

Source: Internet
Author: User
In Ubuntu, there are several files that you can set environment variables


/etc/profile: The first file that is used when the operating system customizes the user's environment at logon, which sets the environment information for each user of the system, and when the user first logs on, the file is executed.

/etc/environment: The second file that the operating system uses at logon, the system sets environment variables for environment files before reading your own profile

~/.profile: The third file that you use when you log on is a. profile file that each user can use to enter shell information that is specific to their own use, and that file executes only once when the user logs on! By default, he sets some environment variables, Executes the user's. bashrc file.

/ETC/BASHRC: This file is executed for each user running the bash shell. When the bash shell is opened, the file is read.

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

There are usually three ways to set up environment variables:
First, temporary settings
Export Path=/home/yan/share/usr/local/arm/3.4.1/bin: $PATH

Global settings for the current user
Open ~/.BASHRC and add rows:
Export Path=/home/yan/share/usr/local/arm/3.4.1/bin: $PATH

Make effective

source. BASHRC
Global Settings for all users
$ vim/etc/profile
In the inside add:
Export Path=/home/yan/share/usr/local/arm/3.4.1/bin: $PATH
Make effective
Source Profile

Test echo $PATH
There are two ways to set the environment variable PATH. The first applies to setting up path for a single user, and the second is to set the path globally.

1. There is a. bashrc file in the user's home directory where the PATH setting can be added to this file as follows:
Open with GEDIT/ROOT/.BASHRC.
Export path= "$PATH:/your path1/:/your path2/..."
Note: Separate each path with ":".

2. Increase in/etc/profile.
Path= "$PATH:/home/zhengb66/bin"
Export PATH
If you want to make immediate effect, use the source command
source. BASHRC
Complete.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

"The above is transferred from" http://blog.mcuol.com/User/For_ATIW/Article/11709_1.htm, and the method described below only takes effect in one terminal, another opens a new terminal to discover path or the original path. To permanently change path See the introduction at the end of this article ~

PS1: The method of directly modifying the contents of the file has not been attempted-for Method 1, because the files installed under the virtual machine do not have root rights to modify the file under/root;
For Method 2, the/etc/profile found in Ubuntu is so bizarre that it doesn't make sense to find anything like "path=***".

PS2: Make a success of yourself--modify it in the form of an order in the terminal:
~$ Echo $PATH # Show Current environment variables
/usr/local/sbin:/usr/local/bin # Display example, multiple paths in the middle of ":" Separated
~$ path= "$PATH:/home/workdir" # Add "/home/workdir" directory
/usr/local/sbin:/usr/local/bin:/home/workdir # Display example, multiple paths are still separated by ":"

is added successfully. (Finally, of course, you can reboot or output to make it effective immediately:)
~$ Export PATH
~$ CD ~
~$ source. BASHRC #该命令需在主目录下才能运行, otherwise the hint cannot be found. BASHRC command
End.

PS3: Write the command when strictly in this form, in the "=" before and after no space, otherwise prompted "Bash:PATH:command not found" error. I have eaten such a ruthless deficit, the main strict compliance with the above method can solve the problem.

"A permanent way to change the path."
Reference http://hi.baidu.com/youjim/blog/item/da912cd98475b3ef39012fad.html

Open ~/.BASHRC file last add command:
Path= $PATH:/home/workdir
Note that unlike all of the above, there is no double quotation mark to restart the solution.
For your safety, please only open the source of a reliable URL

Open Web site Cancel
From: http://hi.baidu.com/%D6%AA%D3%EA%CF%FE%C7%E7/blog/item/11962a9690944815d31b7069.html

roo@ubuntu:~$ Cat/etc/profile
#/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; Todo
If [-R $i]; Then
. $i
Fi
Done
unset I
Fi

If ["$PS 1"]; Then
If ["$BASH"]; Then
ps1= ' \u@\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

Umask 022
roo@ubuntu:~$

roo@ubuntu:~$ cat/etc/environment
Path= "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:"
roo@ubuntu:~$

roo@ubuntu:~$ CD ~
roo@ubuntu:~$ Cat/.profile
Cat:/.profile: No file or directory
roo@ubuntu:~$ Cat. Profile
# ~/.profile:executed by the command interpreter for login shells.
# This file is not read by Bash (1), if ~/.bash_profile or ~/.bash_login
# exists.
# See/usr/share/doc/bash/examples/startup-files for examples.
# The files are located in the Bash-doc package.

# The default umask is set in/etc/profile; For setting the Umask
# for SSH logins, install and configure the Libpam-umask package.
#umask 022

# If running bash
If [-N "$BASH _version"]; Then
# include. BASHRC if it exists
If [f "$HOME/.BASHRC"]; Then
. "$HOME/.BASHRC"
Fi

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.