Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

The PATH is an important concept when working on the command line. It's a list of directories that tell your operating system where to look for programs, so that you can just write script instead of /home/me/bin/script or C:\Users\Me\bin\script. But different operating systems have different ways to add a new directory to it:

Windows

  1. The first step depends which version of Windows you're using:
  • If you're using Windows 8 or 10, press the Windows key, then search for and select "System (Control Panel)".
  • If you're using Windows 7, right click the "Computer" icon on the desktop and click "Properties".
  1. Click "Advanced system settings".
  2. Click "Environment Variables".
  3. Under "System Variables", find the PATH variable, select it, and click "Edit". If there is no PATH variable, click "New".
  4. Add your directory to the beginning of the variable value followed by ; (a semicolon). For example, if the value was C:\Windows\System32, change it to C:\Users\Me\bin;C:\Windows\System32.
  5. Click "OK".
  6. Restart your terminal.

Mac OS X

  1. Open the .bash_profile file in your home directory (for example, /Users/your-user-name/.bash_profile) in a text editor.
  2. Add export PATH="your-dir:$PATH" to the last line of the file, where your-dir is the directory you want to add.
  3. Save the .bash_profile file.
  4. Restart your terminal.

Linux

  1. Open the .bashrc file in your home directory (for example, /home/your-user-name/.bashrc) in a text editor.
  2. Add export PATH="your-dir:$PATH" to the last line of the file, where your-dir is the directory you want to add.
  3. Save the .bashrc file.
  4. Restart your terminal.
@DiegoSkrim666

This comment has been minimized.

Copy link

@DiegoSkrim666 DiegoSkrim666 commented Jan 15, 2020

Oh, nice. Thankyou :)

@FTheodore

This comment has been minimized.

Copy link

@FTheodore FTheodore commented Jan 24, 2020

I would just like to say that you should consider using export PATH="$PATH:your-dir" instead. This will append the new path to the variable. Adding the absolute path to the beginning of the file will make the system search that directory first every time. This is not recommended as it can cause problems with system programs and it adds unnecessary delay.

@Gilbert5262

This comment has been minimized.

Copy link

@Gilbert5262 Gilbert5262 commented Feb 12, 2020

** (gedit:23414): WARNING **: 12:31:52.288: Set document metadata failed: Setting attribute metadata::gedit-encoding not supported

am facing this error when trying to add a path

@FTheodore

This comment has been minimized.

Copy link

@FTheodore FTheodore commented Feb 12, 2020

use nano instead of gedit, gedit has issues when trying to run from tty

** (gedit:23414): WARNING **: 12:31:52.288: Set document metadata failed: Setting attribute metadata::gedit-encoding not supported

am facing this error when trying to add a path

@franciscotv

This comment has been minimized.

Copy link

@franciscotv franciscotv commented Feb 24, 2020

small correction use PATH instead of $PATH in the first parameter after export:
export PATH="$HOME/appl/code/leap-demo-app:$PATH"

@Gilbert5262

This comment has been minimized.

Copy link

@Gilbert5262 Gilbert5262 commented Feb 27, 2020

@franciscotv

This comment has been minimized.

Copy link

@franciscotv franciscotv commented Feb 27, 2020

my pleasure :)
think about why using one instead of the other.

  • assign
  • expand
    that is why, they are different.
@SimonScharf

This comment has been minimized.

Copy link

@SimonScharf SimonScharf commented Jul 20, 2020

I tried following these instructions on my Mac, edited my .bash_profile and appended the line:
export PATH="/Users/.../dart-sass:$PATH" (where ... is the rest of the absolute path of the dart-sass directory)
However, when I run sass --version in terminal, I get the error -bash: sass: command not found.

Am I doing anything wrong? It is very frustrating and confusing.

Edit: Problem was fixed when I tried the line: export PATH="$PATH:/Users/.../dart-sass". I am still confused as to how this fixed the problem though.

@davidenoma

This comment has been minimized.

Copy link

@davidenoma davidenoma commented Aug 16, 2020

for me: on .bashrc
I just added
PATH=$PATH:/directory

@kjcaputa

This comment has been minimized.

Copy link

@kjcaputa kjcaputa commented Sep 22, 2020

You do not have to restart terminal. You can use source command
source ~/.bashrc

@franciscotv

This comment has been minimized.

Copy link

@franciscotv franciscotv commented Sep 22, 2020

@kjcaputa
Thanks!, source command is awesome!
example

@Zorono

This comment has been minimized.

Copy link

@Zorono Zorono commented Nov 15, 2020

Thank you, dude!!
in my case (Ubuntu Desktop 20.10) I just ran the following command in the Terminal PATH="/directory:$PATH"

@TMSantos

This comment has been minimized.

Copy link

@TMSantos TMSantos commented Jan 1, 2021

For those using Z-Shell (zsh) don't forget it's .zshrc instead of .bash_profile

@michee1367

This comment has been minimized.

Copy link

@michee1367 michee1367 commented Feb 4, 2021

thanks

@rafaVls

This comment has been minimized.

Copy link

@rafaVls rafaVls commented Feb 10, 2021

For those using Z-Shell (zsh) don't forget it's .zshrc instead of .bash_profile

This worked for me using zsh, thanks!

@davidliu611

This comment has been minimized.

Copy link

@davidliu611 davidliu611 commented Mar 17, 2021

why do we need to append ":$PATH" at the end?

@Ghasak

This comment has been minimized.

Copy link

@Ghasak Ghasak commented Apr 8, 2021

@davidliu611 This is a simple concatenation of the string in the bash scripting language. You allow the original PATH string to be concatenating with the dir that you specified. check this out using
echo $PATH (in terminal)
you will see that your dir has been added at the beginning of the PATH.
PATH is the location where the system will look for other apps, scripts, env. .etc.

@Screeeech

This comment has been minimized.

Copy link

@Screeeech Screeeech commented Jun 3, 2021

worked great, thank you so much

@ProfJamesMoriarty

This comment has been minimized.

Copy link

@ProfJamesMoriarty ProfJamesMoriarty commented Jun 25, 2021

It is not working for me. I am using kali linux. Do you know what is the problem?

@Midhlaj2006

This comment has been minimized.

Copy link

@Midhlaj2006 Midhlaj2006 commented Jul 7, 2021

Life saver 👍

@JosephBerm

This comment has been minimized.

Copy link

@JosephBerm JosephBerm commented Sep 5, 2021

Excellent work. Thank you for this upload.

@moghaazi

This comment has been minimized.

Copy link

@moghaazi moghaazi commented Sep 9, 2021

For those using Z-Shell (zsh) don't forget it's .zshrc instead of .bash_profile

I love you, I forget that and spent 3 hours trying all solutions, till I read your comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment