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
Question marked as Top-ranking reply

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 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 18, 2015 9:54 AM in response to nofare

The problem isn;t that the command nano is not found, if that was the case the error message would be

sudo nano: command not found. For some reason the complete line


nano /private/etc/hosts


is being see as the command. That is the shell is trying to find a command called 'nano /private/etc/hosts'


This will show it better

bash-3.2$ sudo foo fog

sudo: foo: command not found

bash-3.2$ sudo 'nano /etc'

sudo: nano /etc: command not found

bash-3.2$

a

Nottice in the first line the command foo is not found and that way is reported. In the second command the error message is similar to what you get, the whole line is trying to be run. In this case because of the quotes around nano and /etc


As you have included a screenshot there is no way to see just what exactly is going on. Try running just


sudo nano


that most likely will work. You can also try something like


echo 'sudo nano /private/etc/hosts' | od -c


to see if anything strange is coming up between the last o in nano and the first /


I also suggest you cut and paste the command from the terminal rather then adding a screen capture.

Mar 18, 2015 6:41 PM in response to nofare

But again the error isn;t telling you that the command nano can't be found, it is telling you a command called nano /private/etc/hosts can;t be found. Two very different things.


A few other things to try


run nano /private/etc/hosts directly from the prompt, no sudo. While you won;t have permissions on the file you're looking to see if the error message changes as a clue to want is up.


If it still fails with the SAME error message as you originally received then try running as a different user. This will help narrow the problem down to your environment or to the system.

Mar 18, 2015 7:28 PM in response to Linc Davis

Ah great minds think alike!! See my post above where I wrote

I also suggest you cut and paste the command from the terminal rather then adding a screen capture.


Given the replies from Tony T1 and BobHarris after my post and now this one it is obvious that no no actually reads previous posts. Now I'm new here but are you guys getting paid by the word or do you all just figure no now else has anything worthwhile to say? 😕

Mar 19, 2015 2:32 AM in response to GeoCo

Thank you all for your time and help.

I tried, without sudo, nano /private/etc/hosts and got this (i.e. no error message):


GNU nano 2.0.6 File: /private/etc/hosts


##

# 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 typed in sudo nano and got a blank screen, with at the top, right under the terminal window's top bar:


GNU nano 2.0.6 New Buffer

Mar 19, 2015 12:14 PM in response to nofare

Ideas from prior posters. Could this be some type of keyboard problem? Define a new user and run from the new user.


To further discriminate the problem:


sudo bash
# this put you in root. Type exit when done with root. Be careful with what you type
which nano
nano  /etc/hosts
/usr/bin/nano  /etc/hosts
echo $PATH
file="/etc/hosts"
app="nano "  # note trailing space
$app$file
echo -n $app$file | hexdump -C


output from hexdump

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

0000000f

Mar 19, 2015 1:07 PM in response to nofare

This indicates that sudo is taking the complete line and trying to run it as a command.


A few things to try, enter


sudo echo hello


and see if you get an error message along the same lines as you have been getting ie.


echo hello: command not found.


Make sure you do not have and alias called sudo in your environment. From the prompt enter

alias

and see if anything starting with sudo is shown.


Cut and paste the exact command you are typing in when you run

sudo nano /private/etc/hosts

into a reply window here so we can see if there is anything strange there.


regards

Mar 19, 2015 1:12 PM in response to rccharles

rccharles wrote:


Ideas from prior posters. Could this be some type of keyboard problem? Define a new user and run from the new user.



A keyboard problem could have been a possibility but I would think given that the command works without running it as sudo a keyboard problem seems less likely. A weird keyboard should affect the command with or without sudo, no?


Your idea of running sudo bash is a good one. I'd only add that the first two commands the OP should run after entering


sudo bash


would be


id

env


regards

Mar 19, 2015 1:17 PM in response to BobHarris

I agree that approaching the problem from different angels is a good idea. My only concern is that given the error message the OP is getting the problem is not that nano cannot be found it is that the shell is trying to run the complete line


nano /private/etc/hosts


as a single command. A subtle but important difference.


And of course I realize you folks aren't getting paid, was trying to lighten the mood. Looking back at what I wrote I realize I failed.


regards

Mar 20, 2015 8:03 AM in response to GeoCo

Here we go with the latest tests:


Ran:

sudo echo hello

Result:

hello


Ran:

alias

Result:

Last login: Wed Mar 18 14:50:14 on ttys000

Smith-iMac:~ smithjoe$ sudo echo hello

Password:

hello

Smith-iMac:~ smithjoe$ alias

Smith-iMac:~ smithjoe$


I then ran:

sudo bash

Result:

Smith-iMac:~ smithjoe$ sudo bash

bash-3.2# id

uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procm od),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),701(com.app le.sharepoint.group.1),33(_appstore),98(_lpadmin),100(_lpoperator),204(_develope r),398(com.apple.access_screensharing),399(com.apple.access_ssh)

bash-3.2# env

SHELL=/bin/bash

TERM=xterm-256color

USER=root

SUDO_USER=smithjoe

SUDO_UID=501

SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.TlpRVhfmsD/Listeners

__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0

USERNAME=root

MAIL=/var/mail/root

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

PWD=/Users/smithjoe

LANG=en_GB.UTF-8

SHLVL=1

SUDO_COMMAND=/bin/bash

HOME=/Users/smithjoe

LOGNAME=root

SUDO_GID=20

_=/usr/bin/env


bash-3.2#

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