[terminal] sudo: port: command not found

I recently uninstalled Xcode 4.2 and re-installed Xcode 4.3.1. Command Line Tools are installed. I then installed MacPort using “dmg” disk images for Lion from macports.org. Since, I was getting sudo: port: command not found after every use of port, I followed this and this post to create a .bash_profile file(wasn't present earlier) and then put in it the following but to no avail.

export PATH=$PATH:/opt/local/bin
export MANPATH=$MANPATH:/opt/local/share/man
export INFOPATH=$INFOPATH:/opt/local/share/info 

Following this post

?  ~ git:(master) ? rvm install 1.8.7 --with-openssl-dir=/opt/local
You requested building with '/usr/bin/gcc-4.2' but it is not in your path.
?  ~ git:(master) ? vi .rvmrc 

rvm_archflags="-arch x86_64"

export CC="/usr/bin/gcc-4.2"

export CFLAGS="-O2 -arch x86_64"
export LDFLAGS="-L/opt/local/lib"
export CPPFLAGS="-I/opt/local/include"

Renaming .bash_profile to .profile

?  ~ git:(master) ? vi .bash_profile
?  ~ git:(master) ? mv .bash_profile .profile
?  ~ git:(master) ? mv .profile              
usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory
?  ~ git:(master) ? mv -f .bash_profile .profile
mv: rename .bash_profile to .profile: No such file or directory
?  ~ git:(master) ? port
zsh: correct 'port' to 'pr' [nyae]? n
zsh: command not found: port
?  ~ git:(master) ? which port
port not found
?  ~ git:(master) ? 

.profile content:

export PATH=$PATH:/opt/local/bin
export MANPATH=$MANPATH:/opt/local/share/man
export INFOPATH=$INFOPATH:/opt/local/share/info

This question is related to terminal osx-lion macports xcode4.3 .bash-profile

The answer is


You can quite simply add the line:

source ~/.profile

To the bottom of your shell rc file - if you are using bash then it would be your ~/.bash_profile if you are using zsh it would be your ~/.zshrc

Then open a new Terminal window and type ports -v you should see output that looks like the following:

~ [ port -v                                                                                                              ] 12:12 pm
MacPorts 2.1.3
Entering interactive mode... ("help" for help, "quit" to quit)
[Users/sh] > quit
Goodbye

Hope that helps.


First, you might need to edit your system's PATH

sudo vi /etc/paths

Add 2 following lines:

/opt/local/bin
/opt/local/sbin

Reboot your terminal


If you have just installed macports just run and it should work

source ~/.bash_profile

You could try to source your profile file to update your environment:

$ source ~/.profile

there might be the situation your machine is managed by Puppet or so. Then changing root .profile or .bash_rc file does not work at all. Therefore you could add the following to your .profile file. After that you can use "mydo" instead of "sudo". It works perfectly for me.

function mydo() {
    echo Executing sudo with: "$1" "${@:2}"
    sudo $(which $1) "${@:2}"
}

Visit my page: http://www.danielkoitzsch.de/blog/2016/03/16/sudo-returns-xyz-command-not-found/


if you use zsh.please add flowing string to the line 'export PATH="..."' in file '~/.zshrc'

:/opt/local/bin:/opt/local/sbin

What do you get from running which port as your regular user account? Try it from a freshly opened terminal. Try again after renaming .bash_profile to .profile. Can you run port as a regular user, even with no arguments?


On my machine, port is in /opt/local/bin/port - try typing that into a terminal on its own.


I found the answer in the official website

$ vi ~/.profile

# add the following line
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

And now restart the terminal or type source !$ (equivalent to source ~/.profile)


Examples related to terminal

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave Flutter command not found VSCode Change Default Terminal How to switch Python versions in Terminal? How to open the terminal in Atom? Color theme for VS Code integrated terminal How to edit a text file in my terminal How to open google chrome from terminal? Switch between python 2.7 and python 3.5 on Mac OS X

Examples related to osx-lion

commands not found on zsh Why does cURL return error "(23) Failed writing body"? What is the "Illegal Instruction: 4" error and why does "-mmacosx-version-min=10.x" fix it? Location of the mongodb database on mac How do I timestamp every ping result? How to run iPhone emulator WITHOUT starting Xcode? configure: error: C compiler cannot create executables sudo: port: command not found Disable elastic scrolling in Safari Completely uninstall PostgreSQL 9.0.4 from Mac OSX Lion?

Examples related to macports

pip installs packages successfully, but executables not found from command line What is the difference/usage of homebrew, macports or other package installation tools? Xcode is not currently available from the Software Update server sudo: port: command not found How do I upgrade PHP in Mac OS X? What is the most compatible way to install python modules on a Mac?

Examples related to xcode4.3

lexical or preprocessor issue file not found occurs while archiving? How to create a .gitignore file Code signing is required for product type 'Application' in SDK 'iOS5.1' library not found for -lPods sudo: port: command not found

Examples related to .bash-profile

How to remove entry from $PATH on mac sudo: port: command not found Passing argument to alias in bash Reload .profile in bash shell script (in unix)?