Comments on: Learn How to Set Your $PATH Variables Permanently in Linux https://www.tecmint.com/set-path-variable-linux-permanently/ Tecmint - Linux Howtos, Tutorials, Guides, News, Tips and Tricks. Wed, 03 Jan 2024 14:52:37 +0000 hourly 1 By: Roopid https://www.tecmint.com/set-path-variable-linux-permanently/comment-page-1/#comment-2122067 Wed, 03 Jan 2024 14:52:37 +0000 http://www.tecmint.com/?p=20051#comment-2122067 Here’s my solution, after reading a lot of conflicting advice. Some people say put $PATH changes in .bash_profile (which doesn’t run for a bash shell run from the desktop). Some say put them .bashrc (which does run, probably more than once).

If I simply add a line in .bashrc (I mean /home/roopid/.bashrc):

export PATH="$PATH:/home/roopid/source/rexx:."

Then it gets added twice, which has caused problems when "." is not the last item (I never found out why).

So I use this, which checks whether my changes have already been made:

if ! [[ "$PATH" =~ "source/rexx" ]]
then
    PATH="$PATH:$HOME/source/rexx:."
fi

It adds 2 directories, one for Rexx scripts I use for admin tasks, and "." because I like to include the current directory for commands.

Whole file included below for completeness:-

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi

# Check changes by me (roopid) have not already been made
if ! [[ "$PATH" =~ "source/rexx" ]]
then
    PATH="$PATH:$HOME/source/rexx:."
fi


export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
if [ -d ~/.bashrc.d ]; then
	for rc in ~/.bashrc.d/*; do
		if [ -f "$rc" ]; then
			. "$rc"
		fi
	done
fi

unset rc
]]>
By: Todd https://www.tecmint.com/set-path-variable-linux-permanently/comment-page-1/#comment-1185784 Sat, 29 Jun 2019 18:50:30 +0000 http://www.tecmint.com/?p=20051#comment-1185784 @Ryan

When setting up the Android & Java SDKs on this system I had the same issue when defining the needed PATH variables and adding the library paths. I dug around and found that my current system has both ~/.bashrc and /etc/profile and that no matter what I tried defining them in ~/.bashrc & it wasn’t working, but commenting the lines out in ~/.bashrc and copying them to /etc/profile did exactly as expected.

I came to the conclusion that perhaps there’s an overwrite happening, but I’ve never had a chance to understand it further.

]]>
By: Ryan https://www.tecmint.com/set-path-variable-linux-permanently/comment-page-1/#comment-1184907 Sat, 29 Jun 2019 00:51:53 +0000 http://www.tecmint.com/?p=20051#comment-1184907 Hello,

I am trying to change my $PATH and i did a vi on .bash_profile where i added this command:

export PATH=$PATH:/HOME/scripts

Then I saved the file and then i did a source ~/.bashrc, but my scripts file did not show up when i ran this command.

$ echo $PATH

WHAT did i do wrong? Respectfully request your help.

Thank you.
cajunchief

]]>
By: Shima https://www.tecmint.com/set-path-variable-linux-permanently/comment-page-1/#comment-1151396 Mon, 13 May 2019 17:00:59 +0000 http://www.tecmint.com/?p=20051#comment-1151396 Hi,

My system is Fedora 28 and the default shell is tcsh. I want to know how can I set permanent PATH? It is necessary to say that I do not have root access.

Before, I had Ubuntu, the default shell was BASH. So I used to edit .bashrc file.

Thanks,
Shima

]]>
By: chk666 https://www.tecmint.com/set-path-variable-linux-permanently/comment-page-1/#comment-1001069 Sun, 03 Jun 2018 22:28:10 +0000 http://www.tecmint.com/?p=20051#comment-1001069 Hello and good days.

I need help what happened if i run virtualenv in my environment path, what i mean is “chk@waklu:$ virtualenv” did the path environment is change on bashrc, profile, or even in the /etc/bash, /etc/profile.

The problem is, I cannot detect my python and when i try to echo path should get /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/marin/bin
but I am getting blank, not showing up. Need help I run 16.04 Ubuntu.

]]>