Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux Environment Variables And Their Functions

In Linux, environment variables are dynamic named values that can affect the way running processes behave on a computer. They store information such as the user's home directory, the shell being used, or the default text editor. Environment variables can be created, modified, and deleted by users or programs, and they are often set by the system or by scripts during the initialization process.

Here are some common Linux environment variables and their functions:

  1. PATH: This variable stores a colon-separated list of directories where the system looks for executable files when a command is run. It allows users to run programs without specifying their full paths.

    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    
  2. HOME: This variable points to the current user's home directory, where user-specific configuration files are stored.

    HOME=/home/username
    
  3. USER: This variable contains the current user's username.

    USER=username
    
  4. SHELL: This variable specifies the current user's default shell, such as Bash, Zsh, or Fish.

    SHELL=/bin/bash
    
  5. LANG: This variable sets the system's language and locale, which determines the language used for system messages and the default date, time, and currency formats.

    LANG=en_US.UTF-8
    
  6. EDITOR and VISUAL: These variables define the default text editor to be used by various command-line utilities, such as git, crontab, or visudo. VISUAL takes precedence over EDITOR if both are set.

    EDITOR=/usr/bin/nano
    VISUAL=/usr/bin/vim
    
  7. TERM: This variable specifies the terminal type, which affects the way colors and special characters are displayed.

    TERM=xterm-256color
    
  8. TZ: This variable defines the system's time zone. If not set, the system uses the default time zone specified in /etc/localtime.

    TZ=America/New_York
    
  9. LD_LIBRARY_PATH: This variable contains a list of directories where the dynamic linker should search for shared libraries when loading a program. It is used to override the default library search path.

    LD_LIBRARY_PATH=/opt/custom_libs:/usr/local/lib
    
  10. PS1: This variable defines the command prompt appearance in interactive shells, such as Bash. It can include information like the current username, hostname, or working directory.

PS1='\u@\h:\w\$ '

These are just a few examples of Linux environment variables and their functions. Environment variables play a crucial role in customizing your system, influencing the behavior of programs, and streamlining your workflow.

  1. How to set environment variables in Linux: To set an environment variable for the current shell session:

    export MY_VARIABLE="Hello"
    

    This sets the variable MY_VARIABLE with the value "Hello." To make it persistent across sessions, add the line to your shell configuration file (e.g., .bashrc).

  2. Customizing the shell environment in Linux: Customize the shell environment by adding variable assignments to shell configuration files (e.g., .bashrc, .bash_profile). For example:

    export MY_PATH="/custom/path:$PATH"