3

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
4
  • 1
    Does your user account's shell startup files reset the PATH variable? What shell are you using?
    – Kusalananda
    Commented Apr 27, 2020 at 12:49
  • @Kusalananda Hi, I did echo $0 and it said bash so I am using Bourne Again Shell. bash Commented Apr 27, 2020 at 12:57
  • @Kusalananda I have added the contents of .profile from my user directory. Commented Apr 27, 2020 at 13:06
  • It seems that you are trying to use Kali (from https://www.kali.org: Kali Linux is an open-source, Debian-based Linux distribution geared towards various information security tasks, such as Penetration Testing, Security Research, Computer Forensics and Reverse Engineering. ) as a general purpose Linux system. This is unwise. Rather, install a supported Ubuntu release. You can build or install any of the tools.
    – waltinator
    Commented Oct 20, 2023 at 18:37

3 Answers 3

3

I encountered this problem just recently as well. The default shell of Kali Linux is now zsh. We need to place the

export PATH="$PATH:/path/to/"

inside of .zshrc. Then after implementing the changes by

source ~/.zshrc

and viewing the PATH by echo $PATH, you will see the updated PATH. Verify by restarting the shell.

1
  • Instead of export PATH..., you can also write path+=( /path/to/bin ). Commented Nov 14, 2023 at 18:44
2

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.

3
  • 1
    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. Commented Apr 27, 2020 at 13:25
  • @OpampInverting Welcome, explained here :Using graphical display manager
    – GAD3R
    Commented Apr 27, 2020 at 13:33
  • 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. Commented Oct 1, 2020 at 5:33
0

Recent Kali distribution 2021.1 works with updating $PATH variable in ~/.profile.

Just add PATH=$PATH:"/replace/with/your/path" to ~/.profile

Logout and login or type source ./profile in your home directory.

Check your environment with the env command.

You should see something like below

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/replace/with/your/path
1
  • Recent Kali Linux releases uses zsh as the default login shell. The zsh shell does not read ~/.profile.
    – Kusalananda
    Commented May 21, 2021 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .