Home > php教程 > PHP开发 > body text

Summary of methods for adding environment variables in Linux

高洛峰
Release: 2016-12-15 17:00:33
Original
1601 people have browsed it

Summary of how to add environment variables in Linux

Linux is not sensitive to whether the environment variables have double quotes or whether the variables are enclosed in {}. After a brief look at the profile file, it seems that if the system finds that the variables do not have quotes, it will Automatically added.

But the $ sign must be added before the variable, similar to perl

Three methods of adding environment variables have been tried when using jena in fedora:

1. Use the export command directly:

For example:

export PATH =$PATH:/home/lm/apache-jena-2.7.4/bin

export CLASSPATH=.:/home/liaomeng/apache-jena-2.7.4/lib

The export command can view various system variables and paths , found that there is an additional set path in the PATH in the system variable, and added the CLASSPATH variable, the setting is successful

You can also view the output of a single variable:

echo $CLASSPATH

echo $PATH

2. Modify /etc/ profile file

Add at the end of the /etc/profile file:

export JENAROOT=/home/liaomeng/apache-jena-2.7.4

export PATH=$JENAROOT/bin:$PATH             ##In the existing PATH variable Add the jena path in front, the colon in it is the separator

export CLASSPATH=.:$JENAROOT/lib/jena-core-2.7.4.jar Multiple jar packages need to be added, separated by colons

www.2cto.com

source /etc/profile to make the modification effective without restarting the system

Some people say that it can also be added in the /etc/profile.d/ folder sh file, the /etc/profile file seems to automatically read each script file in the /etc/profile.d/ folder. I haven't tried it yet.

Also note:

The current directory "." in CLASSPATH cannot be lost. Losing the current directory is also a common fatal error.

When setting environment variables, pay special attention not to overwrite the original value. This is a common mistake.

As more software is installed, more and more environment variables are added. In order to avoid confusion, it is recommended that all statements be added at the end of the file and added in the order in which the software is installed.

3. Modify the hidden file ./bashrc in the home directory

The modification method is the same as modifying the /etc/profile file

source .bashrc to make the modification effective

Personally, I think the key is to understand the environment variables of Linux The function when the program is running, and the format must be correct when adding, generally it will not be wrong. For more summary of methods of adding environment variables in Linux, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template