Setting Mac / Unix Environment Variables – Adding Executables to the System Path

After years of resistance I finally caved and bought a sleek, shiny MacBook Pro over the weekend. I’ve been slowly figuring out how to set up my AMES development environment and that means figuring out the basics of using the Unix shell. I struggled to find a simple explanation of how to set environment variables, so I’m inserting a couple of screen grabs which illustrate how to add MTASC and Swfmill to the PATH environment variable.

I downloaded, unzipped and placed the mtasc and swfmill binaries in their respective folders in the following folder:
/usr/local/bin
Method 1 : A Session Variable – Using the bash shell, this adds the mtasc and swfmill binaries to the PATH variable for the current terminal session. When you close the shell and reopen it, you’ll have to add the files to the PATH variable again.

There’s actually a typo in the screen grab–it should be:

export PATH=$PATH:/usr/local/bin/mtasc:/usr/local/bin/swfmill

Method 2: Add to Startup Script – Place the command in a startup script called bashrc which can be found along the path below. The modified PATH will always be available to any bash shell and no further editing is needed.
/etc

This method is similar to how environment variables are set in Windows (without the gui absraction layer). the bashrc file is a simple text file and you simply add the commands to this script which is run everytime the os loads.

I can now reference mtasc or swfmill in the bash sell by simply typing the executable name!Since, I opted for the “set it and forget it” method, I know I at least will benefit from having something to reference the next time I have to set up OSX or Linux (I vaguely remember doing this when I first forayed into Linux a year ago and cursed my laziness at not writing down the process)….maybe there are others out there who have shared the pain of leaving their comfortable Windows double-wide trailer and gone hollywood with the glamorous mac-villa “Made by Apple in California” :)


12 Responses to “ “Setting Mac / Unix Environment Variables – Adding Executables to the System Path”

  1. erixtekila says:

    You’d do it in your home foldre instead.
    That do not need admin privileges.
    cat > ~/.profile
    PATH=$PATH:/usr/local/bin/
    [Control-C]
    That’s all.

    No need to reference all the plain reference, paths suffice here.

  2. Brooks says:

    Very cool–if only I’d known a couple of days ago.

  3. Jake Brumble says:

    Sorry I couldn’t find a more appropriate place to ask my lame rookie question

    swfmill was working with simple tests the first time I tried it, now I am getting errors seeming to indicate no modify/create permission, I have read/write permit for files and folder

    /millfolder/swfmill swf2xml /millfolder/test1.swf

    outputs good result to terminal

    /millfolder/swfmill swf2xml /millfolder/test1.swf|/millfolder/test1.xml

    if test1.xml exists:
    -bash: /millfolder/test1.xml: Permission denied

    if test1.xml does not exists:
    -bash: /millfolder/test1.xml: No such file or directory

  4. Brooks says:

    Hmm, I’m not really sure what your issue is, but I’d probably try to make sure swfmill is set up as unix executable.

    You’ll need to cd to the directory where swfmill is located and then type the following in bash:

    chmod 777 swfmill

    Hopefully that does the trick for you.

  5. Jeff says:

    Hey, thanks for this note. i just bought a new mbp and am struggling … I’m trying to install mit scheme so i can work through sicp, but can’t mv the downloaded file into /usr/local/ through the terminal:

    Jeffs-Computer:~ jeff$ mv ./mit-scheme-20070909-ix86-apple-darwin.tar.gz /usr/local/mit.tar.gz
    mv: rename ./mit-scheme-20070909-ix86-apple-darwin.tar.gz to /usr/local/mit.tar.gz: Permission denied

    i enabled root and try sudo, which doesn’t move the file (?):

    Jeffs-Computer:~ jeff$ sudo mv ./mit-scheme-20070909-ix86-apple-darwin.tar.gz /usr/local/mit.tar.gz
    WARNING: [... blah blah don't use sudo ...]
    Password:
    Jeffs-Computer:~ jeff$ ls /usr/local/
    OpenSourceLicenses OpenSourceVersions

    so, i’m not sure wassup, or if it’s really necessary for me to put the bin in /usr/local/ …

    any ideas?

    jz

  6. Jeff says:

    Oops, should have mentioned i’m using leopard, if that makes a difference.

  7. John Finch says:

    I have seen this permission problem with Leopard. I found that I could log in using sudo via the X11 terminal.

  8. [...] Seetting Mac/Unix Environment Variables Leave a Comment [...]

  9. chris says:

    adding the path via the instructions in comment #1 will wipe out any previous custom settings you may have in your .profile file

  10. sridevi says:

    Do we have seperate method for setting the environment in windowsXP. I am having this particular problem when in run the functiom mpd…
    ??? Error using ==> bookread at 26
    Can’t open file [tempbook.bin]

    Error in ==> mpd at 35
    varargout{1} = bookread(‘tempbook.bin’);

    Error in ==> final_sim_with_noise at 75
    [Book ,residual ,decay] = mpd ( y, 10 ,’D')
    Can someone help, please… we need it to complete our project. thank you….

  11. brooks hanes says:

    thanks Brooks for the post. It is weird, I have never, ever seen another Brooks online.

    Thanks again, was glad to find this post about environ vars as I am setting up CakePHP console.

    Brooks

  12. Brooks says:

    @Brooks Hanes – Good to know there are others out there. ;-) My old man was huge fan of the Orioles Hall of Fame third baseman Brooks Robinson.

Leave a Reply