How to Set Environment Variable For Everyone Under My Linux System

How to set environment variable for everyone under my linux system?

As well as /etc/profile which others have mentioned, some Linux systems now use a directory /etc/profile.d/; any .sh files in there will be sourced by /etc/profile. It's slightly neater to keep your custom environment stuff in these files than to just edit /etc/profile.

How do I permanently add an environment variable?

Edit your ~/.bashrc file and place at the end:

export JAVA_HOME=jdk-install-dir
export PATH=$JAVA_HOME/bin:$PATH

You can even modify /etc/environment if you want it to persist for all users.

Permanently set environment variables for Multiple users

Editing /etc/profile should work, but not recommended.
you should create a new file in /etc/profile.d/ and set the JAVA_HOME there with export.

How to set an environment variable to point to a location and how to set path of an environment variable in UBUNTU?

Yes, the above command sets variable when executing together with other commands like so:

$ VAR1=/home/folder1/lib123.so MY_AWESOME_COMMAND

Or you can use export so that you won't have to include the variable in each command.

$ export VAR1=/home/folder1/lib123.so

Test it below:

$ echo $VAR1
$ /home/folder1/lib123.so

Where are all the places where an environment variable can be set in linux?

As I commented, use

grep -rl VARNAME /etc $HOME

to ask grep to recursively (-r search in file trees recursively) search and list filenames (-l ask grep to just list matching filenames) containing the pattern VARNAME inside /etc (the system-wide configuration directory) and inside your $HOME



Related Topics



Leave a reply



Submit