Home > OS >  Prioritize file in ~/.local/bin over /usr/bin
Prioritize file in ~/.local/bin over /usr/bin

Time:02-01

I'm trying to replace the whoami command with a script that's in ~/.local/bin/. Is there a way to have my whoami get priority so that when I run whoami my script will run instead?

CodePudding user response:

You'll want to put ~/.local/bin/ first in your PATH environment variable. Then that directory will be checked first before any other for programs to run.

export PATH=~/.local/bin:$PATH

CodePudding user response:

This is what I have in my ~/.profile file

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

and this works!

On top of this file, it's written

# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.

So if you have ~/.bash_profile or ~/.bash_login remove them or merge them with ~/profile. I don't have those files.

This is what my $PATH looks like (shortened . . .)

$ echo $PATH | sed -r 's/:/\n/g'| cat -n
     1  /home/shiplu/anaconda3/condabin
     2  /home/shiplu/.sdkman/candidates/gradle/current/bin
     3  /home/shiplu/.cargo/bin
     4  /home/shiplu/.local/bin
     5  /home/shiplu/bin
     6  /usr/local/sbin
     7  /usr/local/bin
     8  /usr/sbin
     9  /usr/bin
    10  /sbin
    11  /bin
    12  /usr/games
    13  /usr/local/games
    14  /snap/bin

Check the path at line 4. It's before any other system bin directories.

  •  Tags:  
  • Related