Marco Masci
Marco Masci

Reputation: 818

How to add a directory to the $PATH variable with macosx leopard

I really am unable to add a directory to the $PATH variable. I have tried to add a text file to etc/paths.d/ containing the path I want to add, but the OS refuses to let me add a file to that directory (permission denied). I don't know why, since I log in as admin...

Please help me, I need to add the adb path for the Android SDK on macosx.

Upvotes: 4

Views: 6099

Answers (1)

Gordon Davisson
Gordon Davisson

Reputation: 126038

The permissions on /etc/paths.d only allow the root account to write to it, not normal admins. This is actually fairly common in OS X, since many users operate day-to-day as admins, but for security reasons it's a bad idea for them to have write access to any settings that can influence system integrity without going through an explicit I-mean-to-do-that step.

So how can you add a file? In general, you need to use a process that promotes to root to do the operation. I'll give three examples:

  1. Create the file someplace else, then use the Finder to move it into place. Since /etc is normally invisible, in the Finder, you'll need to explicitly open it by choosing Go > Go to Folder from the menu, then entering "/etc/paths.d". Then just drag the file into that window, and it'll ask for your admin password (which it uses to promote to root and move the file).
  2. Use TextWrangler or its big brother, BBEdit (the download version, not the Mac App Store version). They have built-in capability to safe files as root (after entering your admin password, just like Finder). If you're going to be manipulating system config files on a regular basis, this is (IMHO) the easiest option.
  3. At the command line, you can use sudo as a prefix to run a command as root (again, after entering your admin password), e.g. sudo cp mypathfile /etc/paths.d or sudo vi /etc/paths.d/mypathfile.

Upvotes: 4

Related Questions