Can't set up environment path variables in Kali Linux installation

8,480

Add the following line to your /etc/environment

PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/user1/Flutter/flutter/bin:/home/user1/android-studio/bin

Explained on debian wiki:

Put all global environment variables, i.e. ones affecting all users, into /etc/environment

Remember, this file is read by PAM, not by a shell. You cannot use shell expansions here. E.g. MAIL=$HOME/Maildir/ will not work!

There is no shell-agnostic and login-independent solution to the problem of how to configure the environment for all users, beyond the trivial cases that PAM can handle.

You can logout then login or source /etc/environment.

Share:
8,480

Related videos on Youtube

OpampInverting
Author by

OpampInverting

Updated on September 18, 2022

Comments

  • OpampInverting
    OpampInverting over 1 year

    I downloaded flutter and Android studio on my linux machine. It is a kali linux installation. I want to add environment path variable for both android studio and flutter permanently so, who when I start a shell, I don't have to add them every time. I want to add to all users. I did some searching and found that you have to add the path in /etc/profile if you want to do for all users. But nothing seems to be working.

    The original content of the file

    # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
    
    if [ "`id -u`" -eq 0 ]; then
        PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    else
        PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
    fi
    export PATH
    
    if [ "${PS1-}" ]; then
        if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
            # The file bash.bashrc already sets the default PS1.
            # PS1='\h:\w\$ '
            if [ -f /etc/bash.bashrc ]; then
                . /etc/bash.bashrc
            fi
        else
            if [ "`id -u`" -eq 0 ]; then
                PS1='# '
            else
                PS1='$ '
            fi
        fi
    fi
    
    if [ -d /etc/profile.d ]; then
        for i in /etc/profile.d/*.sh; do
            if [ -r $i ]; then
                . $i
            fi
        done
        unset i
    fi
    

    I added my paths using a : to separate just after else in line 4 like this

    PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/user1/Flutter/flutter/bin:/home/user1/android-studio/bin"
    

    saved the file and restarted machine, and did

    echo $PATH
    

    in the shell but the output was just this:

    /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    

    Then I tried different method removed previous changes and added

    PATH=$PATH:/home/user1/Flutter/flutter/bin:/home/user1/android-studio/bin
    

    just before export path, saved restarted the machine and it didn't work either. The echo $PATH command prints the same above paths.

    How do I accomplish what I am trying to accomplish. I have looked at several similar questions on this site and most suggest what I have done above. Am I doing anything wrong?

    EDIT This the contents of .profile in my user directory. I have only one user.

    # ~/.profile: executed by the command interpreter for login shells.
    # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
    # exists.
    # see /usr/share/doc/bash/examples/startup-files for examples.
    # the files are located in the bash-doc package.
    
    # the default umask is set in /etc/profile; for setting the umask
    # for ssh logins, install and configure the libpam-umask package.
    #umask 022
    
    # if running bash
    if [ -n "$BASH_VERSION" ]; then
        # include .bashrc if it exists
        if [ -f "$HOME/.bashrc" ]; then
            . "$HOME/.bashrc"
        fi
    fi
    
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
    fi
    
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/.local/bin" ] ; then
        PATH="$HOME/.local/bin:$PATH"
    fi
    
    • Kusalananda
      Kusalananda about 4 years
      Does your user account's shell startup files reset the PATH variable? What shell are you using?
    • OpampInverting
      OpampInverting about 4 years
      @Kusalananda Hi, I did echo $0 and it said bash so I am using Bourne Again Shell. bash
    • OpampInverting
      OpampInverting about 4 years
      @Kusalananda I have added the contents of .profile from my user directory.
  • OpampInverting
    OpampInverting about 4 years
    It worked. Thanks. I had read about etc/environment on other answers but when didn't find the environment file in etc but found profile I thought I will have to edit profile. Also most answers had mentioned profile. I am curious. Why didn't editing the profile work? I also tried added the path in .profile but it still didn't work.
  • GAD3R
    GAD3R about 4 years
    @OpampInverting Welcome, explained here :Using graphical display manager
  • Sean Aitken
    Sean Aitken over 3 years
    I'm having the same issue, and trying to update the PATH in my ~/.profile has no effect. I also have no .bash_login or .bash_profile files. This really seems like a bug in Kali.