Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

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
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 12:05 PM in response to nofare

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 #

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 11:27 AM in response to nofare

So what happened when you did the nano /etc/hosts within the sudo bash command? Nothing? You didn't get the error message.


As GeoCo suggests, you should define a new user and see if that works. You could have something weird/wrong with your system. Any other problems?


If you like playing around without direction, you could try:

You may want to run these "standard" fixes if the problem persists.


1) Check the amount of free space on your harddrive. You should have a several gigs free.


2) You should run disk utility

Macintosh-HD -> Applications -> Utilities -> Disk Utility

a) verify the disk

b) update your permissions.


3) Try a safe boot.

Shutdown your machine. Hold down the shift key. Poweron. Wait awhile; wait awhile while you harddrive

is being checked.

http://support.apple.com/kb/ht1455

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

"'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 ID.