sudo: port: command not found

On MacOSX, if you have installed macports with the package installer, you may encounter the sudo: port: command not found problem.

Macports binaries are installed in /opt/local/bin, so you just need to add this path to your PATH environment variable. Example with your user, add to your $HOME/.profile :

export PATH=$PATH:/opt/local/bin

You can source your profile file to update your environment:

$ source .profile

You are now able to use the port command:

$ sudo port -v selfupdate
  • Fahad

    Awesome, Thank you so much.
    Exactly what I need, and it solved the problem.

    what a nice one line .

  • Pingback: 20130101 sudo: port: command not found « 3D()

  • Guy

    Just what I needed – thank you for posting this 🙂

  • Thank you man, this article very help me.

  • physics user

    Thank you for posting this. It was extremely helpful!

  • Thanks so much for this.

  • Andy

    Thank you vey much!!!

  • Thanks for sharing! Got it working with your tip.

  • haryo

    Thank you!!!

  • Muhammad Muhammad Murtada

    Worked like a charm… Many thanks

  • Xin

    -bash: .profile: No such file or directory

    This happened.


  • CharlyBr

    The .profile file have to be saved in your $HOME directory

  • shubham

    I am new for Mac install using command prompt I execute sudo port install xyz..but it’s giving “sudo: port: command not found”.. i follow and create and new .bash_profile file. but still it’s giving me same error…any suggestion here?

  • CharlyBr

    are you able to locate port binary on your system?

  • KimlengLim

    Thanks a lot

  • Ravi

    Thanks a lot!

  • Josh

    Thanks! Just what I needed.

  • Gustavo

    Thank you very very much.

  • i am using .bash_profile as opposed to just .profile so had to add the line: export PATH=$PATH:/opt/local/bin there and seems to be working. thank you!

  • Pingback: Capistrano & Command Line Poetry Class | Media Zoo()

  • Федот Мармелович

    THANK YOU!!!