Can't add to PATH environment variable

I’m trying to add some directories to my PATH environment variable but it doesn’t seem to be working. This seems to be the main error:

xsel -o -b
Can't add to PATH environment variable

Here is what I have tried:

❯ source .zshenv
...
setopt verbose
exec > >(tee "$DIR"/logfile)
exec 2>&1
...
function pathadd() {
  if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
    PATH="${PATH:+"$PATH:"}$1"
  fi
}
...
pathadd "$HOME"/.local/bin  # for python packages installed with the '--user' option
pathadd "/root/.local/bin"  # for python packages installed globally
...
xsel -o -b
Can't add to PATH environment variable
\00\00\00... 
qe(Be[me[38;2;84;88;98me[48;2;30;34;42m ...

❯ sudo pipx install watch-xfce-xfconf
sudo pipx install watch-xfce-xfconf
creating virtual environment...
installing watch-xfce-xfconf...  

⚠️ Note: '/root/.local/bin' is not on your PATH environment variable. These
apps will not be globally accessible until your PATH is updated. Run `pipx
ensurepath` to automatically add it, or manually modify your PATH in your
shell's config file (i.e. ~/.bashrc).

done! ✨ 🌟 ✨ 
installed package watch-xfce-xfconf 1.0.4, installed using Python 3.11.5
These apps are now globally available
- watch-xfce-xfconf

❯ echo $PATH
echo $PATH
/home/user/.local/bin:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/bin/site\_perl:/usr/bin/vendor\_perl:/usr/bin/core\_perl:/home/user/.cargo/bin

As you can see, I’m trying to add some custom directories to PATH by modifying .zshenv and running source, but it doesn’t seem to be working. When I install a new package with pipx, it warns me that /root/.local/bin is not in PATH. And echo $PATH confirms that my custom additions are not there.

Any ideas what I’m doing wrong or how to properly modify PATH? Thanks!

As a possible solution, I’ve thought about logging the PATH variable at different places in the zsh configuration files to see if that helps. Let me know if you have any other suggestions for things I could try to get the PATH variable to persist correctly.

I’ve read this which seems relevant since I’m using xRDP.

The DISPLAY environment variable is not set. The xsel command requires the DISPLAY environment variable to be set because it interacts with the X server. You can check the value of the DISPLAY environment variable by using the echo $DISPLAY command. If the DISPLAY variable is not set, you can set it using the export DISPLAY=:0 command.

❯ echo $DISPLAY
:10.0

You are asking for trouble here … I don’t think you understand what you are doing …

xsel is a clipboard command - has nothing to do with environment variables

Installing it without sudo works without problem, but that’s not what I’m trying to accomplish.

❯ sudo pipx uninstall watch-xfce-xfconf
sudo pipx uninstall watch-xfce-xfconf
[sudo] password for user:
uninstalled watch-xfce-xfconf! ✨  ✨

❯ pipx install watch-xfce-xfconf
pipx install watch-xfce-xfconf
creating virtual environment...
installing watch-xfce-xfconf...
done! ✨  ✨
  installed package watch-xfce-xfconf 1.0.4, installed using Python 3.11.5
  These apps are now globally available
    - watch-xfce-xfconf

❯ watch-xfce-xfconf
watch-xfce-xfconf
[INFO] You can start modifying 'XFCE 4' settings with 'xfce4-settings-manager'. Your changes will be displayed in this terminal...

You’re trying to add root’s folder to user’s PATH. If that sounds right to you…

Instead of building Rube Goldberg’s machine equivalent scripts to add a string to variable, you should focus more on how to properly do whatever you are doing.

@Individual-Heart-719, have you studied the Archlinux wiki already? No reed to reinvent the wheel.

1 Like