sudo: port: command not found
Asked Answered
I

11

79

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
Inlaw answered 14/3, 2012 at 0:43 Comment(1)
I ran into this error in the command line when installing MongoDB for a Rails app, so I imagine some others may also find this question via Google search with the same keywords. All I did was update XCode and install MacPorts from macports.org, try that before doing anything else on this page.Crimple
N
23

Make sure to delete ~/.bash_profile and ~/.bash_login so that .profile can work. This worked for me http://johnnywey.wordpress.com/2008/04/17/fixing-bash-profile-in-os-x/

Nullity answered 25/3, 2012 at 23:58 Comment(9)
I restarted my terminal and it's gone again :-/Inlaw
what's gone, your .profile? BTW can you still use sudo in the terminal? like sudo ls for example?Nullity
port. I have to run source .profile every time when I open terminal for it to recognize port.Inlaw
sounds like you still have .bash_profile or .bash_login superuser.com/questions/366642/profile-not-loaded-osx-lionNullity
The link to the solution is not available anymore.Diaphaneity
Link to the solution is not available any more. This is why the solution should be posted here and not just the link.Require
Why would you want to delete your ~/.bash_profile or ~/.bash_* for that matter, ever? Especially if you spent a lot of time configuring your bash, all of that configuration will be gone instantly and many tools that you use daily will be gone.Anteater
This is far to be a solution, first of all, you'll gonna delete all your personal profile bash data, and this is not mean it'll gonna work because the problem is related to paths of the system, the correct solution is provided by @Isis.Destine
johnnywey.wordpress.com is no longer available.Mardis
D
148

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

Drollery answered 17/9, 2013 at 10:23 Comment(9)
After lots of .bash_profile investigation, it turned out I just needed to reboot the terminal after installing MacPorts. Thanks for this tip.Octosyllable
It works for me too! Thank you. This should be the right answer.Velarde
@Octosyllable just rebooting terminal worked for me. Thank you for help :)Semanteme
Kindly help me:Bounty: #39288406Nich
Adding those two lines and rebooting the terminal was what finally did the trick after messing around with .bash_profile and .profile. All of it fruitless until I added opt/local/bin to etc/paths.Cologne
You can also add this line to /etc/manpaths: /opt/local/share/manSchoolmarm
For the record, this worked to solve the same problem on High Sierra as well.Joinder
This is the real solution, @Inlaw please tag the correct answer.Destine
It might be a good solution for some cases, but if you do not have sudo access and installed mactools as such, I am afraid another solution would be necessary.Prattle
N
23

Make sure to delete ~/.bash_profile and ~/.bash_login so that .profile can work. This worked for me http://johnnywey.wordpress.com/2008/04/17/fixing-bash-profile-in-os-x/

Nullity answered 25/3, 2012 at 23:58 Comment(9)
I restarted my terminal and it's gone again :-/Inlaw
what's gone, your .profile? BTW can you still use sudo in the terminal? like sudo ls for example?Nullity
port. I have to run source .profile every time when I open terminal for it to recognize port.Inlaw
sounds like you still have .bash_profile or .bash_login superuser.com/questions/366642/profile-not-loaded-osx-lionNullity
The link to the solution is not available anymore.Diaphaneity
Link to the solution is not available any more. This is why the solution should be posted here and not just the link.Require
Why would you want to delete your ~/.bash_profile or ~/.bash_* for that matter, ever? Especially if you spent a lot of time configuring your bash, all of that configuration will be gone instantly and many tools that you use daily will be gone.Anteater
This is far to be a solution, first of all, you'll gonna delete all your personal profile bash data, and this is not mean it'll gonna work because the problem is related to paths of the system, the correct solution is provided by @Isis.Destine
johnnywey.wordpress.com is no longer available.Mardis
G
21

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)

Gunnysack answered 4/10, 2015 at 14:29 Comment(1)
Thank you! This was the only thing that finally helped me. I actually didn't have a .profile, so I created one and added that line and it worked.Heap
C
18

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

$ source ~/.profile
Chemise answered 14/3, 2012 at 0:51 Comment(7)
How do I do source my profile? How do I run this command, just writing it on terminal gives source: no such file or directory: .profileInlaw
move into your user directory with cd $HOME then try itChemise
Yes, I am trying from there only.Inlaw
OP has a .bash_profile, not a .profile. Rename that file to ~/.profile and try again.Sastruga
I renamed it to .profile. Is it different from ~/.profile?Inlaw
It's the same ~/ is just the path to the user directory (same as $HOME/ )Chemise
Kindly help me:Bounty: #39288406Nich
M
18

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

:/opt/local/bin:/opt/local/sbin
Malinda answered 15/3, 2016 at 13:12 Comment(2)
You can also set MANPATH with export MANPATH="/opt/local/share/man". If you want to be able to access MacPorts in non-login shells, set these variables in ~/.zshenv.Schoolmarm
Thanks a lot. I was editing .profile, .bash_profile till now. Finally edited .zshrc and it worked.Jola
M
9

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

Maiamaiah answered 14/3, 2012 at 0:47 Comment(6)
In my bin folder, there are only files(port is a file) ➜ bin ls daemondo port portf portindex portmirrorInlaw
What do you get when you type `set | grep PATH' into a terminal?Maiamaiah
Binary file (standard input) matchesInlaw
Sorry, don't know where to go from there. This might help: willbryant.net/software/mac_os_x/pathsMaiamaiah
I do not have a path.d inside etc folder. I only have macports inside it.Inlaw
there is no /opt folder on my mac Osx 10.8?Botti
E
6

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

source ~/.bash_profile
Enforcement answered 15/1, 2015 at 19:3 Comment(0)
S
1

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?

Sastruga answered 19/3, 2012 at 17:25 Comment(1)
Added it above. It is renamed.Inlaw
E
1

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.

Eberhardt answered 25/6, 2013 at 11:15 Comment(0)
J
0

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/

Jaejaeger answered 16/3, 2016 at 9:4 Comment(0)
X
0

I faced this as an issue with port trees. MacPorts offers a solution here, which worked for me and does not imply changing your environment variables.

Xanthous answered 21/2, 2022 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.