/usr/bin/env: node --harmony: No such file or directory - node.js

I have searched online thru this site and others for a solution, so I finally bow my head and ask for help. It looks like most of the answers are identifying the node/nodejs naming conflict and creating symlinks as a solution. I don't have a nodejs anywhere on my system.
I am using a _ n _ as my node version manager. So,
sudo n
displays a list of installed versions and allows me to choose. n simply copies the chosen version into /usr/local/bin/ as node. It has already established a link from /usr/bin/node to the managed version.
I installed a javascript library called 'waigo.' When I run the following:
waigo init
I get the following output...
/usr/bin/env: node --harmony: No such file or directory
arrgghhh..... I'm frustrated. Any help will be appreciated.

It looks like a problem with the shebang line in a shell script which specifies the program used to interpret the file. This might look like:
#!/usr/bin/env node --harmony
The error message in your case suggests that env is attempting to locate "node --harmony" which was probably a problem with the executable file run when you typed waigo. For example, it might have had a shebang line incorrectly formatted like:
#!/usr/bin/env "node --harmony"

Related

Bash: app definitely on $path, but not found when run

I'm having a issue with a python app that I installed on a empty server.
The package I installed is invoke using pip3 install invoke
After install if I just run invoke without specifying the abs path, then I
get a error: -bash: /usr/bin/invoke: No such file or directory
Running it with the full path to the app works fine.
So I'm confused why it's ignoring the legit app that is in a location
that is definitely on the $PATH.
See the cli commands below for visual reference:
/# invoke
-bash: /usr/bin/invoke: No such file or directory
/# find -name invoke
./usr/local/bin/invoke
./usr/local/lib/python3.6/dist-packages/invoke
/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
/# /usr/local/bin/invoke -V
Invoke 1.4.1
Anyone know what's going on here?
As mentioned in the comments of my original post, this was because the command was previously hashed and bash remembered the old path. Running hash -r was suggested, which resets all mappings. I eventually used hash -d invoke which cleared only that single entry. My reasoning was that I wasn't sure if anything else in the mappings were expected to be there by some other app.
Edit: As pointed out in the comments below, there is no harm in using -r since it's just a faster way to look something up and is saved there once it finds it again anyway.

Where is the "program" module that some bash scripts require before launching Node.JS?

I found a Bash script today that uses the env command to launch Node.JS. The script requires two packages and then uses the second package to parse the process command line arguments before launching node as shown below:
#! /usr/bin/env node
'use strict';
require('zos-lib').Logger.silent(false);
require('./program').parse(process.argv);
I can't find a module/package named './program' anywhere in my file system. Can someone tell me where the program module/package is and what it does? I tried many Google searches but unfortunately program is such a common keyword that I'm not finding anything useful.
UPDATE: slebetman's answer is correct. I wanted to explain why I couldn't find the program module in this update, in case it helps others. As soon as I read his answer about that script being a Javascript script and to look for program.js not program I found it by searching the directory tree from the top level Node.js directory with this command:
$ find . -iname program.js
Unfortunately for me, what you see below is what I tried the first time and that does not produce any output:
$ find . -iname program
The script you found is not a bash script. It is a javascript script. Specifically it is a script written in javascript for node.js.
In node's require system, a module name that begins with ./ means that the module is in the same folder as the script.
You haven't told us the file name of the script you posted. But lets assume it's called myscript.js. Then the folder structure should be:
/whatever/folder/myscript.js
/whatever/folder/program.js
or
/whatever/folder/myscript.js
/whatever/folder/program/index.js
or
/whatever/folder/myscript.js
/whatever/folder/program/package.json
/whatever/folder/program/whatever_script_name.js
If you cannot find the file program.js or the folder program in the same folder as the script you are looking at then you haven't copied the script properly (you forgot to copy the "program" file or folder).

How to change default directory for a command in Bash?

Firstly, I am new to Linux so excuse me if any terminology is wrong; I'll try to phrase the problem as competently as possible.
I have installed Ruby (2.4.0) via Linuxbrew. The ruby command works fine; it installed correctly. However, when I try to use the gem command (which Ruby should have installed) I receive this error:
bash: /usr/bin/gem: No such file or directory
Now, because I installed this with Linuxbrew I know that this directory isn't correct. For example:
result of which gem : /home/me/.linuxbrew/bin/gem
result of which ruby : /home/me/.linuxbrew/bin/ruby
Therefore, it seems gem is installed but the gem command isn't linked to the correct path. I assume I need to direct the gem command to the path of which gem as opposed to /usr/bin/gem that bash is saying doesn't exist. How would I go about changing this? I tried in vain to change the bash_profile but I'm not sure what to do.
Again, excuse me if ruby and gem are not referred to as commands and if the problem isn't the "default directory" as stated in the title. I wasn't sure how to label it.
EDIT/TL;DR:
Basically, how can I make gem execute this: /home/me/.linuxbrew/bin/gem instead of looking for the program in /usr/bin/gem?
Instead of running gem, run /home/me/.linuxbrew/bin/gem, i.e. type the full path name (followed by any arguments you may need).
If this becomes too tiresome, you could change your PATH. Prepend your bin directory with
PATH=$HOME/.linuxbrew/bin:$PATH
First, the reason you get the error /usr/bin/gem not found, is that earlier in the same shell session, the file used to be there. Bash will cache this to speed things up when running the same command many times. Running hash -r will clear this.
Editing PATH you seem to have managed, hence the which command gives the result it does.
To answer my own question-
As I had previously installed and uninstalled Ruby via apt-get instead of Linuxbrew in the same Terminal window, Bash was looking for gem in usr/bin as opposed to the path specified in my bash_profile to Linuxbrew.
Therefore, Stian's answer above with hash -r would also work, I am sure.

teach me how to set up a path correctly

I installed casperjs by npm install command on my mac os x.
But, when I try using casperjs in command line, it gives me the error below.
$ casperjs cas.js
-bash: /usr/local/bin/casperjs: No such file or directory
I checked if casperjs is installed by using which command.
The result is below.
$ which casperjs
-bash: /Users/Hayato/.nodebrew/current/bin/casperjs
I think what I need to do is to setup a path in a different way so that when I run "casperjs test.js", it runs "/Users/Hayato/.nodebrew/current/bin/casperjs" instead of "/usr/local/bin/casperjs".
But, I'm not familiar with this kind of terminal task, and don't know how to do this.
Please could anyone teach me how to setup a path correctly?
Thanks!
If you want to use casperjs in the directory you specified, add this to your ~/.bash_profile
export PATH=/Users/Hayato/.nodebrew/current/bin/:$PATH
Save the file
That will add all scripts in the /Users/Hayato/.nodebrew/current/bin directory to your path.
After that.. close the terminal and then reopen it:
You can check the path by doing:
echo $PATH
You should see the path you just added.
Then when you do the following:
which casperjs
it should use the new location.
Let me know if this works for you!
But, the issue may be something deeper, did you get errors when you installed casperjs via brew?
You may want to try linking it again using
brew link casperjs
If that doesn't work you may have some permission issues.
Check out these previously answered questions:
brew link didn't complete
Fixing homebrew permissions

How to tersely run a globally installed Node.js app

I was recently using mongo-express which is written in Node.js. I've installed it globally following instructions on their GitHub page. It says in order to run it:
cd YOUR_PATH/node_modules/mongo-express/ && node app.js
I was wondering if there's any workarounds to avoid changing directory to the app's folder first (using cd).
By the way, in npm's doc, it says
When in global mode, executables are linked into {prefix}/bin on Unix.
In my case (using mac), executable app.js is linked into /usr/local/bin. But if I just type app.js in the command line trying to run it, it'd say -bash: /usr/local/bin/app.js: Permission denied. Even if this works, wouldn't app.js be a too generic name and become conflicted with other apps later?
Thanks for helping.

Resources