Trouble adding to PATH variable

I seem to particulary dense in understanding what appears to be fairly simply in these instructions Environment variables - ArchWiki.

I installed ConTeXt under my home user directory and need to set the path as
export PATH=/home/gary/programs/context/context-linux-64/tex/texmf-linux-64/bin:$PATH

to run it from any where in the current session. I got this from the installation instructions and it works for the current session.

After reboot “which context” returns “/usr/bin/context”. After executing the export, “which context” returns the new path.

To make it permanent, I tried adding the export to ~/.bashrc (following https://linuxconfig.org/how-to-add-directory-path-to-path-variable) but cannot get it to work. Not by running source ~/.bashrc or rebooting.

I’m sure I’m being stupid, here, but would you please point me to it? Thank you.

Should’ve included that, if try to do so in ~/.bash_profile, then the path appears in echo $path but it’s still not using it. I had context installed through textlive but uninstalled it when installing the full package directly from pragma ade site.

#1 I presume you are using the bash shell, otherwise .bash_profile would be ignored.

#2 PATH changes generally should go in the profile, not the rc file. I have used both, but the profile is more correct.

#3 Can you show your .bash_profile so we can look at the PATH variables there? Also, showing us the content of the PATH variable in your shell might help. Both please.

Thank you for responding.
The bash_profile is only

#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc
source "$HOME/.cargo/env"

I added at the end
export PATH="${PATH}:/home/gary/programs/context/context-linux-64/tex/texmf-linux-64/bin"

But I don’t know what the bash shell is. All I know is that I use Konsole when I need the command line. I’ll post the path variable in a moment; have to reboot because messed with it and don’t know how to undo that. Thank you.

Here it is, thanks.

echo $path
/home/gary/.cargo/bin /home/gary/.local/bin /usr/local/sbin /usr/local/bin /usr/bin /usr/lib/jvm/default/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl

My default is zsh, so in .zshrc I have this:

export PATH="$PATH:$HOME/Dropbox/Admin/Scripts" 

That means I can just type ‘a15’ (which is the filename for a script that manages my phone bluetooth audio connection) and it launches like an installed program via krunner.

It starts by saying that PATH is whatever is already defined, the colon adds another URL to the path.

These items are then also readily available in a TTY.

2 Likes
echo $SHELL

will tell what your shell is. If it is:

/bin/zsh

then you need to insert your line into ~/.zshrc instead of ~/.bashrc

:footprints:

3 Likes

Thank you.

echo $SHELL                                                                                                                                                                                      
/bin/bash

So, I tried the syntax provided by @Ben in the bash_profile and, after reboot, the

echo $PATH                                                                                                                                                                                       
/home/gary/.cargo/bin:/home/gary/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/gary/programs/context/context-linux-64/tex/texmf-linux-64/bin

shows the new path as the last entry. However, still get

which context                                                                                                                                                                                   
/usr/bin/context

Could this mean that, even though I uninstalled texlive’s version of context, there may still be some files in that path? Running context fails because of startup error : no format file given, quitting.
[EDIT:Added later, found an older version of ConTeXt in /usr/bin/context and, after deleting it, the new path now works. Perhaps, it was left over as a dependency to pandoc?]

It runs if the export is run in the CLI for the session.

Thank you.

I don’t know if this matters but every time I run source .bash_profile–even if change nothing in the file–these errors are shown:

/home/gary/.bashrc:type:64: bad option: -P
/home/gary/.bashrc:105: command not found: shopt
/home/gary/.bashrc:107: command not found: shopt
/home/gary/.bashrc:112: command not found: shopt

line 64 is if type -P dircolors >/dev/null ; then

It uses by default on Manjaro zsh, it is configured in some kind of profile for Konsole. Since it is special to Konsole, you can’t use environment variables to determine which shell you are using.

3 Likes

Please check the shell with echo $0, as it’s more accurate (except when used in a script).

shopt is a bash builtin so it looks like you’re using another shell, presumably zsh. So the PATH export should go in ~/.zshrc (or whatever file your shell uses).

type doesn’t seem to have any options, so remove the -P.

However that’s in your .bashrc which is the wrong file.

1 Like

Thank you. I see, now; and that is what @xabbu was telling me also.

echo $0                                                                                                                                                               
/bin/zsh

Adding the export to the bash_profile “worked” in that Context could be run from anywhere. But I commented those lines out of the file, rebooted to ensure that Context could not be run elsewhere, and then added the export (the original line) to .zshrc. Executing source .zshrc ran without error and Context could be run from anywhere; and it remained so after a restart.

May I ask a follow-up, please? Using the original export as suggested in the install package from the pragma ade site, export PATH=/home/gary/programs/context/context-linux-64/tex/texmf-linux-64/bin:$PATH, rewrites the PATH by prepending the new path to the string. This differs from the sytax given by @Ben which appends the new path to the end of PATH.

Does it make a difference? I assume that in the prepend, the Context executable that was in usr/bin/ could have been left there to be called from an application that used it as a dependency (like pandoc) or would that application still be following the PATH and run the same one?

Thank you.

Pretty much, but the PATH is more for us than software.

It’s a convenience feature of shells. Instead of typing the full path to the executable, we just type the filename. The shell then searches the PATH one directory at a time until it finds the first file that matches, then it stops searching and uses that file.

You can call things in different ways

$ command  # shell searches PATH for the first file called "command"

# absolute path
$ /usr/bin/command # shell uses /usr/bin/command

# relative path
$ ./command # shell uses the file "command" from the current directory

if in any case the shell can’t find a matching file you get an error.

AFAIK it’s mostly used by shells, but I suppose it depends on how the software is written.

At least with some languages, if the app passes a command without a path to the underlying shell then the shell will search the PATH.

1 Like

The $PATH is sourced from left to right, so if you add the additional directory to the end while the file exists in /usr/bin, then the version in /usr/bin will be used.

1 Like