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
How to Remove Cached Credentials from Git
Format and Then Convert Txt to CSV Using Shell Script and Awk
How to Change the Output Color of Echo in Linux
How to Pass the Password to Su/Sudo/Ssh Without Overriding the Tty
Bash Ignoring Error for a Particular Command
How to Use Variables in Bash Sed Command, Specific Example
How to Prompt For Yes/No/Cancel Input in a Linux Shell Script
How to Generate a Core Dump in Linux on a Segmentation Fault
Print a File, Skipping the First X Lines, in Bash
What Happens If You Use the 32-Bit Int 0X80 Linux Abi in 64-Bit Code
Iterate Over a List of Files With Spaces
How to Remove the Lines Which Appear on File B from Another File A
Finding Number Is Even/Odd in Assembly
Glibc Scanf Segmentation Faults When Called from a Function That Doesn't Align Rsp
What Is the Meaning of "Posix"