u936293
u936293

Reputation: 16234

#!/usr/bin/env: No such file or directory

The shebang line in my bin/www file is:

pi:~/ferc$ head -n 1 bin/www
#!/usr/bin/env node

However, executing it:

pi:~/ferc$ bin/www
bin/www: line 1: #!/usr/bin/env: No such file or directory

The env file does exist:

pi:~/ferc$ ls -lL /usr/bin/env
-rwxr-xr-x 1 root root 31408 Feb 18  2016 /usr/bin/env

The node file also exists:

pi:~/ferc$ ls -al /usr/bin/node
lrwxrwxrwx 1 root root 15 Jul  7 18:29 /usr/bin/node -> /usr/bin/nodejs

And node runs fine:

pi:~/ferc$ node -v
v4.2.6

What does the error message really mean? Which file is it complaining about?

Upvotes: 2

Views: 3872

Answers (2)

u936293
u936293

Reputation: 16234

The cause was a corrupted file, probably due to a mixture of LF and CF/LF line endings in the file.

What happened were:

  1. I copied the file from a Windows PC to the AWS ec2 Ubuntu instance.
  2. First time I ran the www file, that same error message appeared. The cause at this point was probably the node executable did not exist. I hadn't created the symbolic link yet.
  3. While trying to troubleshoot, I edited and saved the www file using nano. I think at this point the file got corrupted.
  4. Later, I added the symbolic link for /usr/bin/node. However, the same error persisted, but probably due to the corrupted line endings.
  5. I dos2unix the www file, and the error went away.

Upvotes: 1

Alex Blex
Alex Blex

Reputation: 37048

You can use node directly like:

#!/usr/bin/node

See pros and cons: https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my

Upvotes: 0

Related Questions