Skip navigation

Trying to set up ~/bin directory

1735 Views 24 Replies Latest reply: Nov 4, 2013 11:02 AM by etresoft RSS
1 2 Previous Next
EMF_321 Level 1 Level 1 (0 points)
Currently Being Moderated
Oct 31, 2013 9:21 PM

Hello all,

 

I'm trying set up my local bin directory like I have it in Ubuntu, so I can store my scripts that allow me to run them like regular bash commands.  I've look around the forums and google and feel more confused.  I've upgraded to Mavericks and am not sure which file to make my edits to.  /etc/paths, /etc/paths.d, /etc/bashrc, ...

 

In Ubuntu all I had to do was edit my ~/.bashrc file with the following :

 

export PATH=$PATH:/home/myUserName/bin

 

# Alias definitions.

# You may want to put all your additions into a separate file like

# ~/.bash_aliases, instead of adding them here directly.

# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then

   . ~/.bash_aliases

fi

 

It would be a pain to put all of my scripts in /bin folder and chmod o+w myScript.sh.  I also feel like that is bad practice.  Any help would be greatly appreciated.

 

Thanks

-E

MacBook Air (13-inch Mid 2011), OS X Mavericks (10.9)
  • Drew Reece Level 4 Level 4 (1,195 points)
    Currently Being Moderated
    Oct 31, 2013 10:11 PM (in response to EMF_321)

    It's unix, you can do the same

    Stick em in the bin & chmod them the same as Linux.

     

    I tend to use ~/.bash_profile & ~/.bashrc depending on which way the wind blows.

     

    On 10.6.8 I have (I haven't setup 10.9 yet, but its probably the same)…

    $ cat .bashrc

    # Add path so that remote shells can see tools!

    PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/X11/bin

    # System-wide .bashrc file for interactive bash(1) shells.

    if [ -z "$PS1" ]; then

       return

    fi

    PS1='\h:\W \u\$ '

    # Make bash check its window size after a process completes

    shopt -s checkwinsize

     

    The ~/.bash_profile has the PATH appended too & all the aliases for local shells.

    You definitely want to avoid adding to /bin - it's Apples & they may squash you with updates. Go for /usr/local/bin if you want global executables.

     

    The /etc files are default versions, copy them to override ~/ if you want to edit them.

  • Jeffrey Jones2 Level 6 Level 6 (8,425 points)
    Currently Being Moderated
    Nov 1, 2013 12:56 PM (in response to EMF_321)

    bash only reads ~/.bashrc when you open non-login shell. A new Terminal window opens a login shell, so use ~/.bash_profile.

  • Tony T1 Level 6 Level 6 (8,125 points)
    Currently Being Moderated
    Nov 1, 2013 1:36 PM (in response to Jeffrey Jones2)

    Another way is to add a file with paths to /etc/paths.d

     

         sudo nano /etc/paths.d/mypaths

         In nano, enter the path:  /Users/Tony/bin

         ^O, [enter]

         ^X

     

    Exit Terminal, Open a new Terminal window, and check with: echo $PATH

     

     

    nano will look like:

         Screen Shot 2013-11-01 at 4.31.21 PM.png

  • VikingOSX Level 5 Level 5 (4,700 points)
    Currently Being Moderated
    Nov 1, 2013 1:32 PM (in response to EMF_321)

    Contents of my .bash_profile:

     

    [[ -s ~/.bashrc ]] && source ~/.bashrc

     

    All the good stuff is in my ~/.bashrc, including the following line:

     

    export PATH=.:~/bin:$PATH

  • Drew Reece Level 4 Level 4 (1,195 points)
    Currently Being Moderated
    Nov 1, 2013 1:54 PM (in response to Tony T1)

    Tony T1 wrote:

     

    Another (easier, better) way is to add a file with paths to /etc/paths.d

     

     

    Doesn't that add a single users search path to every user on the system?

     

    Since you have to create bin/ in your home folder the default permissions will allow all other user to read into it. It strikes me as bordering on unexpected behavior?

     

    OS X is multi user, so shouldn't each users environmental variables like search paths be independant?

     

    If you want system level executables isn't that the whole point of storing them in /usr/local? You can simply add that path which ever /etc/file is most appropriate (bashrc, paths.d, bash_profile…).

     

    For the most part I don't think this is an issue, until you try setting it up in a school or true multiuser environment, but I dont think it is best practice. Otherwise I could just drop a script called 'cd' into my ~/bin & annoy every other Terminal user on the system (assuming the search path picks up my ~/bin/cd before the system /usr/bin/cd). 

  • Tony T1 Level 6 Level 6 (8,125 points)
    Currently Being Moderated
    Nov 1, 2013 2:03 PM (in response to Drew Reece)

    Good point

    Better to add the path to: ~/.bash_profile

  • Drew Reece Level 4 Level 4 (1,195 points)
    Currently Being Moderated
    Nov 1, 2013 1:59 PM (in response to Tony T1)

    Thank heavens, I thought I had gone off on a tangent.

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Nov 1, 2013 4:47 PM (in response to EMF_321)

    Just remember that it is not Ubuntu. The Mac is a different philosophy. Apple handles all of the system directories. You stay out of those unless you are willing to re-apply your changes after each update. The /etc/paths.d location is a neat trick, but I never use it. I find it better to run everything out of a user account. If you need something to be stand-alone, then make it stand-alone. Don't try to modify the system.

     

    Always use ~ or $HOME. That will work on all platforms and will make your scripts more portable.

  • Drew Reece Level 4 Level 4 (1,195 points)
    Currently Being Moderated
    Nov 1, 2013 6:44 PM (in response to etresoft)

    I'm sure this has been said elsewhere already, but thanks for making etrecheck.

     

    It's so handy for getting an overview, if it could go into the App Store it would be perfect, some users refuse to download apps from the web so they don't get help.

     

    I can't direct message you so apologies to the other users in this thread.

    (I'm referring to - http://www.etresoft.com/etrecheck - see what your OS is running).

  • Mark Jalbert Level 5 Level 5 (4,385 points)
    Currently Being Moderated
    Nov 2, 2013 4:41 AM (in response to EMF_321)

    It would be a pain to put all of my scripts in /bin folder and chmod o+w myScript.sh.  I also feel like that is bad practice.  Any help would be greatly appreciated.

    Personally, I don't have a $HOME/bin. I develop scripts in my home folder then install them in /usr/local/bin. If I need to modify a script then I do that in my home folder then install the modified script in /usr/local/bin.

  • BobHarris Level 6 Level 6 (12,505 points)
    Currently Being Moderated
    Nov 2, 2013 5:49 AM (in response to Mark Jalbert)

    I actually have a $HOME/local/bin. :-)

     

    In a corporate setting, I run into development systems where my home directory is NFS mounted and the systems I connect to have their own NFS mounted /usr/local/bin, so I cannot add stuff to them.

     

    If I want an open source package not provided by the IT group (current versions of Vim, bash, …), I can not use /usr/local/bin, so I need local/bin, local/lib, local/src, … place of my own.

     

    Things get a little more complicated, for executables, as I often bounce between Linux, Solaris SPARC, Solaris x86, and AIX systems. For this situation I have a local/arch/…/bin where my .bash_profile constructs my PATH with the correct 'arch' path for the type of machine I'm running on. 

     

    My point is that you can control your $HOME, you can not always control your /etc, nor your /usr/local.

  • Mark Jalbert Level 5 Level 5 (4,385 points)
    Currently Being Moderated
    Nov 4, 2013 6:30 AM (in response to BobHarris)

    I actually have a $HOME/local/bin. :-)

    Well, that's fine. Whatever your requirements demand. I was offering an alternate solution, since path_helper (ugh) adds /usr/local/bin to the PATH variable even if the directory does not exist.

     

    BTW, do you also install MacPorts in your home folder?....}:-)>

  • BobHarris Level 6 Level 6 (12,505 points)
    Currently Being Moderated
    Nov 4, 2013 7:16 AM (in response to Mark Jalbert)

    BTW, do you also install MacPorts in your home folder?....}:-)>

    No.  My iMac is a lone island in a corporation full of Windows and Linux workstations, with Solaris and AIX target platforms for a cross platform product.  I do not need to export my Mac binaries :-)

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Nov 4, 2013 7:32 AM (in response to Mark Jalbert)

    Mark Jalbert wrote:

     

    BTW, do you also install MacPorts in your home folder?....}:-)>

    People still use MacPorts? I build all my tools myself. Command line tools go into ~/bin. Frameworks go into ~/Library/Frameworks. I even have some things in ~/Applications.

1 2 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.