Debian $PATH variable change
Asked Answered
C

5

21

How can I change the $PATH variable in Debian? I tried to change /etc/profile but this affected only normal users (and yes, I added path to BOTH user's and root's paths).

After that I tried to edit /root/.profile and then /root/.bashrc also ...

Neither worked. Do you know where could be problem?

Caroleecarolin answered 31/8, 2011 at 13:47 Comment(5)
Which shell is this for? Bash, csh other ?Prickly
Hmm I'm not sure :D I'm 'begginer' with UNIX ... I didn't change this from default instalation so what it could be ? ... edit: after doing "echo $SHELL" I got output "/bin/bash" :)Caroleecarolin
Just a guess, but did you start a new bash after the edit? Or alternatively did you source the modified file after it was edited (. /path/to/file or source /path/to/file).Fibula
Yes I logged out and then also restarted the server. I didn't try source but I did now and it doesn't work also. Btw I said that it work's for normal users - it doesn't affect only root account.Caroleecarolin
I found out something interesting. When I do echo $PATH it outputs the default $PATH but when I do printenv PATH then I get the $PATH which I want ...Caroleecarolin
R
25

This is set in the /etc/login.defs on debian 6.0 .

These are the lines you have to edit:

# *REQUIRED*  The default PATH settings, for superuser and normal users.
#
# (they are minimal, add the rest in the shell startup files)
ENV_SUPATH      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV_PATH        PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

EDIT:

I forgot to put where I found the solution: https://serverfault.com/questions/166383/how-set-path-for-all-users-in-debian

Rutherfordium answered 11/1, 2013 at 15:6 Comment(2)
thank you for your response, I won't verify it but I think that this is what I was looking for :-)Caroleecarolin
Does not work for me with Debian 12, lmde6Cowry
L
3

Modify /etc/environment to include a line like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
Literality answered 6/8, 2013 at 11:29 Comment(0)
P
2

If you are using a graphical display manager / GUI (a.k.a not just a shell or terminal) changing the /etc/profile, ~/.bashrc or other file will not change the PATH variable.

In this case you have to create the file: ~/.xsessionrc file and add something like this:

export  PATH="$PATH:/sbin"

(depending on the path you want to add)

For more info: https://wiki.debian.org/EnvironmentVariables

NOTE for Debian 10, check out this solution first if you get command not found:

su - root instead of su root

https://unix.stackexchange.com/questions/482569/debian-10-buster-update-grub-command-not-found

Pete answered 29/7, 2019 at 16:23 Comment(0)
G
1

Simple way for me was to create file /etc/default/su with content

ALWAYS_SET_PATH yes

so I do not have to meddle with system files directly.

Gyrate answered 20/9, 2021 at 9:39 Comment(0)
H
0

I'm working on this Debian version;

yuandre-server@yuandre-server:/usr/sbin$ uname -a

Linux yuandre-server 6.1.0-21-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64 GNU/Linux

Create this file;

sudo vim ~/.bashrc

And add this line end of the file;

export PATH="$PATH:<what_do_you_add>"

This configure will work for all users.

You can also execute them as a single command;

sudo echo 'export PATH="$PATH:<what_do_you_add>"' >> ~/.bashrc && source ~/.bashrc && cat ~/.bashrc | grep PATH

This source ~/.bashrc command will be reload your shell session.

Hi answered 9/5 at 12:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.