Linux Basic Commands

Environment Variables

1. list all variables

$ printenv         or just        $env

 

2. start application with specific environment variable

$ env EDITOR=vim xterm

 

3. set environment variable

# export NODE_PATH=/usr/local/include/node:/usr/local/lib/node_modules

 

 

4. delete environment variable

# unset NODE_PATH

 

5. print value of environment variable

$ echo NODE_PATH

 

6. Append value to en existing env. variable

# NODE_PATH=$NODEPATH:<new value>

 

7. reset all variables to default on login (be carefull)

$ env -i bash

 

 

 

 

 

Where are environment variables are stored?

The kernel stores the list of environment variables and their values for each process, and inherit them to child processes. They exist at runtime, and are not stored in some file or so. But there is a virtual file in

/proc/<pid>/environ

Which contains all the environment variables. The kernel makes them visible by that virtual file. One can list them. For example to view the variables of process 3940, one can do

cat /proc/3940/environ | tr '\0' '\n'

Each variable is delimited by a binary zero from the next one. tr replaces the zero into a newline.

 

 

 

 

Persistent variables

if you want some environment to be started after boot, put bash commands into ~/.bashrc file:

 

 

 

More at https://help.ubuntu.com/community/EnvironmentVariables