Environment Variables
Environment variables in Linux are dynamic values that can affect the way running processes behave on a computer. They are used to store configuration settings and can be accessed by applications and scripts to modify their behavior based on the environment they are running in.
karchunt@kcserver:~$ env
SHELL=/bin/bash
WSL2_GUI_APPS_ENABLED=1
WSL_DISTRO_NAME=Ubuntu
WT_SESSION=d21de821-e3d5-4bfc-a89a-e6af4dacef06
NAME=kcserver
PWD=/home/karchunt
LOGNAME=karchunt
HOME=/home/karchunt
LANG=C.UTF-8
WSL_INTEROP=/run/WSL/511_interop
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:
WAYLAND_DISPLAY=wayland-0
LESSCLOSE=/usr/bin/lesspipe %s %s
TERM=xterm-256color
LESSOPEN=| /usr/bin/lesspipe %s
USER=karchunt
DISPLAY=:0
SHLVL=1
XDG_RUNTIME_DIR=/run/user/1000/
WSLENV=WT_SESSION:WT_PROFILE_ID:
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Python313/Scripts/:/mnt/c/Python313/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA App/NvDLISR:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Program Files/nodejs/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Users/karchunt/.local/bin:/mnt/c/Users/karchunt/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/karchunt/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/msys64/ucrt64/bin:/mnt/c/Users/karchunt/AppData/Roaming/npm:/mnt/c/Users/karchunt/AppData/Local/Microsoft/WinGet/Packages/Gyan.FFmpeg.Essentials_Microsoft.Winget.Source_8wekyb3d8bbwe/ffmpeg-8.0-essentials_build/bin:/mnt/c/Users/karchunt/AppData/Roaming/Python/Python313/Scripts:/mnt/c/Users/karchunt/AppData/Local/Programs/Antigravity/bin:/snap/bin
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
HOSTTYPE=x86_64
PULSE_SERVER=unix:/mnt/wslg/PulseServer
WT_PROFILE_ID={dd0ed5a2-64ae-59a9-b912-8732a7a6dfdd}
_=/usr/bin/envCreate Environment Variables
You can create environment variables in Linux using the export command in the terminal. For example:
karchunt@kcserver:~$ export MY_VARIABLE="Hello, World!"
karchunt@kcserver:~$ echo $MY_VARIABLEIf you want to persist the environment variable after a reboot, you can add the export command to your shell’s configuration file (e.g, ~/.bashrc, ~/.profile, ~/.bash_profile).
- For system wide environment variables, you can add them to
/etc/environmentor create a new file in/etc/profile.d/.
Remove Environment Variables
To remove an environment variable, you can use the unset command. For example:
karchunt@kcserver:~$ unset MY_VARIABLE
karchunt@kcserver:~$ echo $MY_VARIABLEPATH Environment Variable
The PATH environment variable is a special variable that tells the shell where to look for executable files when you run a command. It contains a colon-separated list of directories. When you type a command, the shell searches through these directories in order to find the executable file.
You can view the current PATH variable by running:
karchunt@kcserver:~$ echo $PATHIf you’re trying to execute a command that’s not found, you may need to add the directory containing that command to your PATH variable. You can do this by using the export command:
karchunt@kcserver:~$ export PATH=$PATH:/new/directory/pathThis command appends /new/directory/path to the existing PATH variable. To make this change permanent, add the export command to your shell’s configuration file as mentioned earlier.
Here is what you can know the command path.
karchunt@kcserver:~$ which python3
/usr/bin/python3
karchunt@kcserver:~$ export PATH=$PATH:/usr/bin/python3