Add environment variables to Ubuntu

Source: Internet
Author: User

Http://www.linuxidc.com/Linux/2012-05/61263.htm

Environment variable settings in Ubuntu 12.04 LTS:

1. Set the current user environment variable (invalid for root users)

Open the terminal and enter:
Www.linuxidc.com @ linuxidc :~ $ Sudo gedit ~ /. Bashrc
[Sudo] password for www.linuxidc.com:

Add at the end:
Export Path =/opt/embedsky/4.3.3/bin: $ path
Where/opt/embedsky/4.3.3/bin is the environment variable path you need to set.

To make it effective immediately, run the following command on the terminal:
Www.linuxidc.com @ linuxidc :~ $ Source ~ /. Bashrc
Or restart your computer.

2. Set system environment variables (effective for root users)

Open the terminal and enter:
Www.linuxidc.com @ linuxidc :~ $ Sudo gedit/etc/environment
[Sudo] password for www.linuxidc.com:

Add "colon:" add "your environment variable path" at the end of Path = "...".

To make it effective immediately, run the following command on the terminal:
Www.linuxidc.com @ linuxidc :~ $ Source/etc/environment
Or restart your computer.

........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ ........................................................................................................................ .............................................................................................

Environment variable configuration file for Ubuntu Linux:
/Etc/profile: The first file used by the operating system to customize the user environment during login. This file sets environment information for each user in the system. When the user logs on for the first time, the file is executed.

/Etc/environment: the second file used by the operating system during logon. Before the System reads your own profile, it sets the environment variable of the Environment File.

~ /. Profile: The third file used for logon is. profile file. Each user can use this file to input shell information dedicated to their own use. When a user logs on, this file is only executed once! By default, it sets some environment variables to execute the user's. bashrc file.

/Etc/bashrc: execute this file for every user running bash shell. When bash shell is opened, the file is read.

~ /. Bashrc: This file contains bash information dedicated to your bash shell. This file is read when you log on and every time you open a new shell.

How to set the PATH environment variable:

Method 1: The. profile or. bashrc file in the user's main directory (recommended)

Log on to your user (non-root) and enter:
$ Sudo gedit ~ /. Profile (or. bashrc)
You can add the path at the end of this file as follows:
Export Path = "$ path: Your path1: Your path2 ..."
Save the file, log out, and log on again. The variable takes effect.
The variables added in this method are only valid for the current user.

Method 2: profile files in the system directory (Exercise caution)

There is a profile file under the etc directory of the system to edit the file:
$ Sudo gedit/etc/profile
Add the path settings as follows:
Export Path = "$ path: Your path1: Your path2 ..."
After the file is edited and saved, restart the system and the variable takes effect.
The variables added in this method are valid for all users.

Method 3: Environment files in the system directory (Exercise caution)

In the etc directory of the system, there is an environment file to edit it:
$ Sudo gedit/etc/environment
Find the following PATH variable:
Path = "<...>"
Modify the PATH variable and add your own path to it. For example:
Path = "<...>: Your path1: Your path2... "
Each path is separated by a colon. This file also takes effect after being restarted, affecting all users.
Note that export Path =… is not added here... .

Method 4: Enter

$ Sudo export Path = "$ path: Your path1: Your path2... "
This method takes effect immediately, but the setting becomes invalid after the user logs out or the system restarts. This method is suitable for setting temporary variables.

Note: You must be cautious when modifying methods 2 and 3, especially through the root user. If the modification is incorrect, it may cause some serious system errors. Therefore, the first method is recommended. In addition, it is best not to develop embedded Linux under root (unless you are very familiar with Linux !!), To avoid serious system errors caused by improper operations.

The following is an example of the problem caused by incorrect modification to the environment file and the solution:

Problem: you cannot log on because you accidentally set environment variables in etc/environment.
Tip: Do not set export path in etc/environment. This will cause the system to fail to log on after restart.
Solution:
On the logon interface, press Alt + Ctrl + F1 to enter the command mode. If it is not required by the root user, enter the command mode. (the root user is not allowed to enter the command mode. gedit editing will not be displayed)
/Usr/bin/sudo/usr/bin/VI/etc/environment
Move the cursor to the export path ** row, and delete the row two times in a row by D;
Input: WQ save and exit;
Then type/sbin/reboot to restart the system (need to boot may be prompted, and power off will be taken directly at this time)

 

From: http://my.oschina.net/qinlinwang/blog/30471

 

Most of my recent use cases are ~ /. Profile

Sudo gedit ~ /. Profile

Then add: Export Path = "$ path: mtpath"

Restart the system.

Run the program in the complete path when no environment variable is enabled.

View environment variables: Echo $ path

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.