You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

"'sudo: nano' command not found" issue.

Hello,


Having an issue with a "command not found problem" (see bellow).

User uploaded file


I ran the echo $PATH command to get a sense of things (see bellow).

User uploaded file

Any idea on how I might fix the command not found issue I'm encountering when I try to access the Hosts file?

Thank you!

iMac, iOS 8.2

Posted on Mar 18, 2015 8:49 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 20, 2015 12:05 PM

Surprise what I entered is valid bash 😉.


Here is what I see on the terminal with the exception of nano edit screen. nano is invoked, but the output goes away when the nano edit ends. the command exit returns you from being in root. Enter one command at a time. You may want to copy and paste to the terminal window.


me $ sudo bash
Password:
root # which nano
/usr/bin/nano
root # nano /etc/hosts
root # /usr/bin/nano /etc/hosts
root # echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/Developer/Tools:/usr/X11R6/bin:/Developer/Tools
root # # construct nano string.  Can see what is in the string later.
root # file="/etc/hosts" 
root # app="nano "  # note trailing space
root # # will invoke nano.   
root # $app$file
root # # see what exactly is in the string.
root # echo -n $app$file | hexdump -C
00000000  6e 61 6e 6f 20 2f 65 74  63 2f 68 6f 73 74 73     |nano /etc/hosts|
0000000f
root #
38 replies

Mar 20, 2015 11:13 AM in response to nofare

Everything there looks normal.


In addition to RC Charles suggestions please post a cut and paste of the complete line you enter when you get the error message. Without that there is no further I can go with this. Include the line before and the line after the command similar to what I did in my first post above.


regards

Mar 20, 2015 11:22 AM in response to rccharles

Not sure I understand what you're requesting RC:


Type in sudo bash, which will let me in root. Then, type in which nano, then type in nano /etc/hosts, then type in, one after the other, the rest of the lines you list, from number 05 to number 10, before typing exit at the very end?


Sorry for the quite likely silly confusion.

Mar 20, 2015 11:32 AM in response to GeoCo

Oops, I just replied to GeoCo, so hopefully he will forget me 😊


Try the following:

script tmp.log

sudo nano /private/etc/hosts

...

exit

Then provide the hexdump output from the tmp.log

/usr/bin/hexdump -C tmp.log

The 'script' command will start a new command prompt, but capture everything that happens next in the 'tmp.log' file.

You then try your 'sudo' command.

When you are back at your command prompt, enter 'exit' to terminate capturing your output into 'tmp.log'


Finally, you use 'hexdump -C' to dump the captured data in hex. If there are any funny characters, they will show up.


I expect the output from hexdump will look something like:

hexdump -C tmp.log

00000000 6d 79 70 72 6f 6d 6f 74 3a 7e 20 6d 79 75 73 65 |mypromot:~ myuse|

00000010 72 6e 61 6d 65 24 20 73 75 64 6f 20 6e 61 6e 6f |rname$ sudo nano|

00000020 20 2f 70 72 69 76 61 74 65 2f 65 74 63 2f 68 6f | /private/etc/ho|

00000030 73 74 73 0a 73 75 64 6f 3a 20 6e 61 6e 6f 20 2f |sts.sudo: nano /|

00000040 70 72 69 76 61 74 65 2f 65 74 63 2f 68 6f 73 74 |private/etc/host|

00000050 73 3a 20 63 6f 6d 6d 61 6e 64 20 6e 6f 74 20 66 |s: command not f|

00000060 6f 75 6e 64 0a 6d 79 70 72 6f 6d 70 74 3a 7e 20 |ound.myprompt:~ |

00000070 6d 79 75 73 65 72 6e 61 6d 65 24 20 65 78 69 74 |myusername$ exit|

00000080 0a |.|

00000081

It will not be exactly this as I made up the tmp.log file for this example.

Mar 20, 2015 6:36 PM in response to BobHarris

BobHarris wrote:


Oops, I just replied to GeoCo, so hopefully he will forget me 😊

Never!! Once I gather enough points to storm the lounge you're in for it, that's for sure 😀


Anyway back to the OP, without the OP cutting and pasting the EXACT line that is entered (and the surrounding context) into a post here there we're all just doing that thing into the wind that gets you all wet.


So nofare, not sure why you are reluctant to do this one easy step that evil go a long way towards solving this but that is your choice.


regards

Mar 21, 2015 4:24 AM in response to rccharles

Thanks everyone again for your generous time and efforts. I really appreciate it.

And yes, GeoCo, I'm ready to solve this little issue ... if at all possible.


GeoCo, here's what I got for "copy and paste the exact line that leads to the error message":




Last login: Fri Mar 20 13:45:53 on ttys000


Smith-iMac:~ smithjoe$ sudo nano /private/etc/hosts


Password:


sudo: nano /private/etc/hosts: command not found


Smith-iMac:~ smithjoe$




As for RC's request ... including the cut and paste request from GeoCo:




Last login: Fri Mar 20 13:45:53 on ttys000


Smith-iMac:~ smithjoe$ sudo nano /private/etc/hosts


Password:


sudo: nano /private/etc/hosts: command not found


Smith-iMac:~ smithjoe$ sudo bash


bash-3.2# which nano


/usr/bin/nano


bash-3.2# nano /etc/hosts


bash-3.2# /usr/bin/nano /etc/hosts


bash-3.2# echo $PATH


/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin


bash-3.2# file="/etc/hosts"


bash-3.2# app="nano "


bash-3.2# $app$file


bash-3.2# echo -n $app$file | hexdump -C


00000000 6e 61 6e 6f 20 2f 65 74 63 2f 68 6f 73 74 73 |nano /etc/hosts|


0000000f


bash-3.2# exit


exit


Smith-iMac:~ smithjoe$

Mar 21, 2015 6:56 AM in response to nofare

Hmm, curious and curious.


Cutting and pasting the line

sudo nano /private/etc/hosts

from your post into my terminal window works. And looking at the hex dump shows nothing out of the ordinary.


Not sure if we had you try this but in case we didn't try entering


sudo /usr/bin/nano /private/etc/hosts


Also try this to determine if this is a problem with your account or with the system you are on: create another user account with admin privileges, log into that account and try the command.


Let us know what happens then.


regards

Mar 21, 2015 4:03 PM in response to GeoCo

After running sudo nano /private/etc/hosts, I got:

##

# Host Database

#

# localhost is used to configure the loopback interface

# when the system is booting. Do not change this entry.

##

127.0.0.1 localhost

255.255.255.255 broadcasthost

::1 localhost



I then set up a new user with admin privileges and got this, i.e. the exact same error message.



Last login: Sat Mar 21 22:03:52 on ttys000

Smith-iMac:~ PaulRingo$ sudo nano /private/etc/hosts


WARNING: Improper use of the sudo command could lead to data loss

or the deletion of important system files. Please double-check your

typing when using sudo. Type "man sudo" for more information.


To proceed, enter your password, or type Ctrl-C to abort.


Password:

sudo: nano /private/etc/hosts: command not found

Smith-iMac:~ PaulRingo$



So, at this point ... kinda stumped.

I'm going to try RC's suggestions and, well, hopefully the permission thing will help. Will report back.


Thanks again.

Mar 21, 2015 5:40 PM in response to rccharles

Well, there are other shells around. Perhaps, bash is bashed.


# invoke different shell.
mac $  tcsh
[macForRobert:~] mac% sudo nano /etc/hosts
Password:
# now nano comes up with the /etc/hosts file.
# all the shells are listed here for me.  note: sh is a duplicate of bash.
# also, csh, ksh, zsh beside tcsh
[macForRobert:~] mac% ls /bin



did you try both /etc/hosts and /private/etc/hosts ? They are the same file. /etc is linked to /private/etc


You could try textwrangler. It has a root mode which I have not used. Have just textwangler command line command.


Robert

Mar 22, 2015 8:44 AM in response to nofare

nofare wrote:


After running sudo nano /private/etc/hosts, I got:

Wow, lets take a full stop here. Are you saying that when you cut and pasted the line from my post into your terminal window the command worked?


Need to clarify this before doing anything else.

I then set up a new user with admin privileges and got this, i.e. the exact same error message.


When you tried it in the new user account did you cut an paste my command or enter it from your keyboard? (assuming the command worked when you cut and pasted)


So, at this point ... kinda stumped.

I'm going to try RC's suggestions and, well, hopefully the permission thing will help. Will report back.


Thanks again.

If it is working when you cut and paste from my post but does not work when you enter it from your keyboard this is strange as you would expect other commends to misbehave also.


Give the other ideas a shot, don't overlook Linc's suggest to try it in safe mode, always a good idea.

Mar 23, 2015 1:16 AM in response to GeoCo

Well, it looks like it's all fixed really. Not sure how.

I indeed did manage to access the Hosts file after running sudo nano /private/etc/hosts. So it worked ... so well in fact that I didn't notice it at first (that's how clueless I am with Unix commands). Still, I don't know what did the trick: the sequence of sudo bash + which nano + nano /etc/hosts ?


Who should I give the "This Solved My Question" mark? I wish I could give it to a few people, but ... there can be only one.

Mar 23, 2015 6:55 AM in response to nofare

Glad it is working for you now but hate it went there is no actual resolution 😟 Are you sure you did nothing that might have affected the problem? Did you do the safe boot at any time?


Has for the points, The awarding of points (specifically the solved points) serves two purposes, one it is a way to acknowledge and 'reward' in some small way the person who fixed your problem. The second, and possibly more import use of marking a post as solving the issue is to point future users to the post that solved your problem.


Remember ASC serve two purposes, one is to get your problem fixed but equally as important is to serve as a place you can come to and search for solutions for problems without having to go through the, as in this case, long drawn out back and forth. If posts could;t be marked as solving an issue a user would have to go through and read each thread looking to see if the issue was resolved. But on the other hand marking a post as solving an issue when it didn't will also make the system less efficient.


So in this case I would recommend you mark your last post as solved or add one last post explaining that the issue self resolved and mark that as solved. Doing this is OK, you won;t get the points of course but as least future user will know what happened.


As for the two helpfuls if you found any of the suggestions you got during this helpful then go ahead and mark those as such. Pointing out techniques or other troubleshooting ideas that you found worthwhile will help future readers.


Regards

"'sudo: nano' command not found" issue.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.