I have the following PATH.


I want to unset one of these variables is this the following way to do it:

unset PATH=/homejosemserrajr/anaconda3/bin:

2 Answers 2


PATH is actually a single variable, which has a string value. The value consists of directory paths, which are separated with colons (:).

Usually, your PATH variable is defined and exported in the ~/.profile file, which you can edit with your favorite text editor. If you cannot find the place where /home/josemserrajr/anaconda3/bin is added, you can reset the PATH variable and explicitly remove that path from the string with a command such as the following:

export PATH="$(echo "$PATH" | sed 's|/home/josemserrajr/anaconda3/bin||g' | sed 's|^:*||' | sed 's|:*$||')"

The command uses a bit of bash and sed to do the following:

  1. Remove all occurrences of the string /home/josemserrajr/anaconda3/bin from the current PATH value.
  2. Remove any (0 or more) leading colons (matched by the regular expression ^:*) from the resulting string of step 1.
  3. Remove any (0 or more) trailing colons (matched by the regular expression :*$) from the resulting string of step 2.
  4. Save the resulting string from step 3 into the PATH variable (overwriting the old value).
  5. Export the new PATH value to your environment, so that applications can access it.

By adding this command to the end of your ~/.profile file you should be able to remove the unwanted path from your PATH variable.


You can use parameter expansion to remove a substring from the value of a variable. For example, given

echo "$var"

then to remove the first instance of substring /homejosemserrajr/anaconda3/bin:, you could use

$ echo "${var/\/homejosemserrajr\/anaconda3\/bin:}"

(note the backslashes to escape literal slashes in the path). To apply this to your PATH,


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .