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

Can I have certain settings that are universal for all my users?

NSIS – How to set an environment variable in system variable

I want to set the environment variable in system variable path for my application. How can I set that using nsis? For example: C:/Program Files/Sample/bin, I want to set this path in System variable.

How to set Tomcat environment variable to System environment property?

This is my VM argument from the the tomcat server and i want to set this variable to my system environment. please if any one knows any other option let me know. -Denv.demo.url=tcp://localhost:61616?

Why doesnt “export” works in linux system() cmd to set a linux shell environment variable at runtime?

I was trying to set a linux shell environment variable at run time in software using system() command. In the target, couldn’t see it set. for eg. snprintf(buf, sizeof(buf), export A=%s, luck); sy

how can i convert my grails application from http to https under Linux operating system?

how can i convert my grails application from http to https under Linux operating system

How to set system environment variable in C#?

I’m trying to set a system environment variable in my application, but get an SecurityException. I tested everything I found in google – without success. Here is my code (note, that I’m administrator

How do I set a system environment variable in Windows XP without using the “My Computer” Dialog

I’m switching between different Java SDKs (1.4.2, 1.5.0 and 1.6.0) for various projects. I would like to set the JAVA_HOME environment variable on my Windows XP machine without going through the tedio

How to programatically set a permanent environment variable in Linux?

I am writing a little install script for some software. All it does is unpack a target tar, and then i want to permanently set some environment variables – principally the location of the unpacked lib

reinitialize system wide environment variable in linux

I just want my apache to register some of my predefined environment so that i can retrieve it using getenv function in php. How can i do this? I tried adding /etc/profile.d/ with export FOO=/bar

How do I set an Win32 system environment variable in Perl?

I want to be able to set a system environment variable in Perl and I wrote the following script (inspired from this idea) to accomplish this: use Win32; use Win32::API; use Win32::OLE qw( in ); my $ma

How to set the path environment variable from ant script

How to set the path environment variable from ant script


Amazingly, Unix and Linux do not actually have a place to set global environment variables. The best you can do is arrange for any specific shell to have a site-specific initialization.

If you put it in /etc/profile, that will take care of things for most posix-compatible shell users. This is probably “good enough” for non-critical purposes.

But anyone with a csh or tcsh shell won’t see it, and I don’t believe csh has a global initialization file.

Some interesting excerpts from the bash manpage:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The –noprofile option may be used when the shell is started to inhibit this behavior.

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the –norc option. The –rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.

So have a look at /etc/profile or /etc/bash.bashrc, these files are the right places for global settings. Put something like this in them to set up an environement variable:

export MY_VAR=xxx

Every process running under the Linux kernel receives its own, unique environment that it inherits from its parent. In this case, the parent will be either a shell itself (spawning a sub shell), or the ‘login’ program (on a typical system).

As each process’ environment is protected, there is no way to ‘inject’ an environmental variable to every running process, so even if you modify the default shell .rc / profile, it won’t go into effect until each process exits and reloads its start up settings.

Look in /etc/ to modify the default start up variables for any particular shell. Just realize that users can (and often do) change them in their individual settings.

Unix is designed to obey the user, within limits.

NB: Bash is not the only shell on your system. Pay careful attention to what the /bin/sh symbolic link actually points to. On many systems, this could actually be dash which is (by default, with no special invocation) POSIXLY correct. Therefore, you should take care to modify both defaults, or scripts that start with /bin/sh will not inherit your global defaults. Similarly, take care to avoid syntax that only bash understands when editing both, aka avoiding bashisms.

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.

man 8 pam_env

man 5 pam_env.conf

If all login services use PAM, and all login services have session required in their respective /etc/pam.d/* configuration files, then all login sessions will have some environment variables set as specified in pam_env’s configuration file.

On most modern Linux distributions, this is all there by default — just add your desired global environment variables to /etc/security/pam_env.conf.

This works regardless of the user’s shell, and works for graphical logins too (if xdm/kdm/gdm/entrance/… is set up like this).

Using PAM is execellent.

# modify the display PAM
$ cat /etc/security/pam_env.conf 
# BEFORE: $ export DISPLAY=:0.0 && python /var/tmp/myproject/ &
# AFTER : $ python $abc/ &
abc   DEFAULT=/var/tmp/myproject

If you are working on ubuntu type this command ~/.bashrc (if you are using gedit you could type gedit ~/.bashrc) then write the environment variable that you want to persist across all terminal sessions eg export variable=”2015″

If your LinuxOS has this file:


You can use it to permanently set environmental variables for all users.

Extracted from: