On my Mac I use an Admin and an everyday User account (without admin / sudo privileges). Currently I am setting up a new Yosemite system and found that after installing MacPorts (using its installer), I cannot do sudo operations, such as sudo port selfupdate. In the user account it tells me that it does not have sufficient privileges and on the admin account the command port is not found.

So I am wondering what is the correct way to set up MacPorts on OS X? Should I install it rather on the Admin instead of the User account? Or is there some other way to use it from the User account?

1 Answer 1



Macports is installed as root and uses its own account macports for some things. It does not use your account for anything.

To do MacPorts actions e.g. install, selfupdate you need to run it as root. Which in this case is run via sudo. So to do these actions you do need an admin account.

To use MacPorts executables or libraries you just need to add MacPorts to your user environment, which is the same for any user on your machine. e.g. add /opt/local/bin to $PATH to put the executables on your path, as described in the MacPorts manual.

The one edge case is the install from the disk image which will run a script on your current user to add a line to your .bash_profile to set up your path.
You can also manually add the following line to your Admin's .bash_profile:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
  • If you added the user to the sudoers file, wouldn't that not give them admin access in OS X, just on the command line?
    – Spotlight
    Dec 24, 2014 at 16:20
  • sudo can be invoked from a non-admin account without messing with sudoers. It just becomes a two-step process. Use su -l adminname to escalate just the Terminal session to admin level, and then use sudo normally. It means you need to enter your admin password twice to get to root, but you don't need to weaken security by futzing with sudoers.
    – ganbustein
    Dec 25, 2014 at 2:56
  • Thank you for the explanation and helpful answer. Adding the $PATH variable to the Admin's .bash_profile did the trick.
    – n1000
    Dec 25, 2014 at 10:02
  • 1
    @awesomebing1 - Only if you gave them ALL privileges. If you restricted them to a smaller set of Cmnd_Alias commands, like to run all or some port commands, then you limit the scope of access.
    – jla
    Jan 12, 2016 at 19:32
  • @ganbustein - In order to switch user (su) to an admin login (-l adminname) you have to know that admin user's password. Nothing you do or don't do to the sudoers file can weaken the security anymore than that. You may as well give the user admin privileges in the sudoers file at that point. At least that way they wouldn't have to know the admin user's password.
    – jla
    Jan 12, 2016 at 19:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .