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” :)

8 Comments

  1. Posted May 24, 2006 at 4:51 pm | Permalink

    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. Posted May 25, 2006 at 1:52 am | Permalink

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

  3. Jake Brumble
    Posted March 20, 2007 at 2:41 am | Permalink

    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. Posted March 20, 2007 at 11:42 pm | Permalink

    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
    Posted November 18, 2007 at 8:45 pm | Permalink

    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
    Posted November 18, 2007 at 8:47 pm | Permalink

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

  7. John Finch
    Posted December 1, 2007 at 7:44 am | Permalink

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

  8. Posted July 18, 2008 at 1:03 pm | Permalink

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

One Trackback

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*