开发者

setting envirnoment variable in linux

开发者 https://www.devze.com 2022-12-08 14:31 出处:网络
Hai Linux, I wrote a small c program using gcc compiler and i named开发者_StackOverflow the executable has hello

Hai Linux,

I wrote a small c program using gcc compiler and i named开发者_StackOverflow the executable has hello i want this hello to be executed from any place . How to set the environment variable in bash shell?.

while installing some software it has it's own envirnoment variable how to set that?.

Thank you in advance.


You add the path to the executable to the PATH environment variable. For example, assuming a bash shell, and the path to the program /home/username/program/hello, you do the following:

export PATH=$PATH:/home/username/program

If you want this to be set automatically, add that line to ~/.bash_profile


If you're using bash (and you probably are if you're running Linux), the first thing you should do is change your ~/.bash_profile to include your own binary directory in the path.

Add the following line to the end of it:

export PATH=$PATH:~/bin

Then create that directory with:

mkdir ~/bin

Then put whatever executables you want to use into that directory. Voila, whenever you log in, they will be available.

Keep in mind that bash will search your path for the first runnable program with that name so, if you want to make an awk, ls or cp command, you'll need your ~/bin directory to come before the system directories in your path. But this is usually a bad idea - better to name your executables so they don't clash with real ones (until you know what you're doing of course, then you can replace or trap system executables to your heart's content).

In answer to your update as to how to set an environment variable, it's a simple (in bash):

export name=value

which will create an enviroment variable name and give it the value value. It's worth using export rather than set since that makes it available to sub-processes.


In bash its:

export name=value
0

精彩评论

暂无评论...
验证码 换一张
取 消