23

So, what I am trying to do is to create a personal bin directory at my home folder. I created the following folder:

/Users/thi/bin

I put my scripts in this folder, but if I type in the Terminal:

myScript

It doesn't run.

I was told I have to export this bin path, something related to echo $PATH, but I don't know how to do it.

bneely
  • 3,973
Thi G.
  • 2,284

3 Answers3

24

You need to add the following to file ~/.profile:

export PATH=/Users/thi/bin:$PATH

Then source ~/.profile

Note, that you may need to create this file, and because it begins with a . it might not be visible in the finder for editing via an application like a text editor. To list all files including hidden ones, use:

ls -la ~/
stuffe
  • 25,668
tfjgeorge
  • 364
  • 3
  • 2
  • If I add export PATH=/Users/thi/bin:$PATH to my .bashrc file, is it gonnae work? Is it correct? – Thi G. Aug 23 '13 at 12:50
  • 12
    Better use $HOME/bin instead of /Users/thi/bin. You'll then be able to copy your settings to another machine, where your user name is perhaps different. – lhf Aug 23 '13 at 13:00
  • If I type in the terminal: PATH=$HOME/bin:$PATH and then type: export PATH. Will it do the trick? – Thi G. Aug 23 '13 at 14:31
  • 1
    If you do that, it will change the settings now, but not on future boots. To change the path in a way that survives reboots, you need to include those commands in your .profile file. – Daniel Aug 23 '13 at 16:30
  • Thks!! And why do I have to run "source ~/.profile"? What does it do? @DanielLawson – Thi G. Aug 23 '13 at 16:33
  • source ~/.profile will apply the new/changed .profile file to your current shell session. You only need to do that to see your changes take effect without opening a new Terminal session. – Dan J Aug 23 '13 at 18:20
  • 2
    Great, thank you all for the answers. I added export PATH=$HOME/bin:$PATH to my $HOME/.bash_profile. – Thi G. Aug 24 '13 at 12:46
  • launchd gets its path from '/etc/launchd.conf' or 2) if your scripts don't inherit the $PATH you may need to add 'source "$HOME/.profile"' to the top of your scripts.
  • – TJ Luoma Aug 28 '13 at 16:14