/opt/homebrew/bin/node: No such file or directory - node.js

I installed node using brew install node#18
when i
cd /opt/homebrew/bin
and then run node, I see node terminal for me to run command but when i execute
/opt/homebrew/bin/node from a shell script
I see below mentioned error
/opt/homebrew/bin/node: No such file or directory
Following is my .zshrc
I have done sourcing of .zshrc
Restarted but my .sh file with the /opt/homebrew/bin/node command is still failing.
Can Anyone help please?

Related

Facing "yarn not found" error while using terminal every time in mac

I want to use 'yarn' package manager to manage packages in my react-native project. I have successfully installed yarn package manager in my Mac by this command "npm install --global yarn" and set the env path by this command export PATH=/Users/admin/.npm-global/bin:$PATH.
All good I am able to use yarn after that.
The problem is when I again try to open terminal later than again it shows the "bash: yarn: command not found" and I need to set env path.
So how I set path permanently in my Mac, so that later I don't need to set env path again and again.
Anyone please help me.
You need to add export PATH=/Users/admin/.npm-global/bin:$PATH to your .bashrc file, in your home directory:
cat 'export PATH="/Users/admin/.npm-global/bin:$PATH"' >> ~/.bashrc
The content of the .bashrc file is run each time bash is started. (except maybe for login shells. In the case of a login shell, I believe .profile is run instead)

Running a bash script (with some npm commands in it) in Ubuntu by double-clicking on the bash-file runs into `npm: command not found` error

I am currently trying to set up my system so I can run my bash file (startWebApp.bash) on Ubuntu by double-clicking on it. Unfortunately, that is not working, but when I run the script in the terminal with ./startWebApp.bash it works fine.
The underlying problem seems to be that the $PATH variable is different when running the script by double-clicking on the file. The $PATH variable when I run the file in my Terminal is:
/home/magonba/.nvm/versions/node/v14.17.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
While when I run the file by double-clicking on it, $PATH is:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Why is there a difference and how can I change that?
Reproduction steps:
Create the file startWebApp.bash with the following content:
#!/bin/bash
sudo service postgresql restart
cd /home/my/project/folder/nodejsapp
npm start &
cd /home/my/project/folder/vuejsapp
npm run serve &
I set in the File Manager under Preferences -> Behavior -> Executable Text Files to Ask what to do (in order to be able to start the application by double-clicking on it).
When I double-click on the file, Ubuntu offers me the options: Run in Terminal, Display, Cancel and Run
I choose Run in Terminal (because I need to provide a password since I am using a sudo command)
Runs into the error(s):
/home/my/project/folder/nodejsapp/startWebApp.bash: line 6: npm: command not found
/home/my/project/folder/vuejsapp/startWebApp.bash: line 8: npm: command not found
Thanks for any help in advance!
The problem you got here is, that nvm is integrated in you .bashrc. But when you run your bash file from the GUI, your bashrc will be ignored, and a very minimal bash shell is started. You can fix this in multiple ways.
Install npm to a system installation path (e.g. with apt)
Change your $PATH in the script
#!/bin/bash
PATH="/home/magonba/.nvm/versions/node/v14.17.6/bin:$PATH"
sudo service postgresql restart
cd /home/my/project/folder/nodejsapp
npm start &
cd /home/my/project/folder/vuejsapp
npm run serve &
Every time you call npm, give the full path
#!/bin/bash
sudo service postgresql restart
cd /home/my/project/folder/nodejsapp
/home/magonba/.nvm/versions/node/v14.17.6/bin/npm start &
cd /home/my/project/folder/vuejsapp
/home/magonba/.nvm/versions/node/v14.17.6/bin/npm run serve &
Include your .bashrc in your script
#!/bin/bash
. /home/magonba/.bashrc
sudo service postgresql restart
cd /home/my/project/folder/nodejsapp
npm start &
cd /home/my/project/folder/vuejsapp
npm run serve &
Please note.
If you go for solution 2 or 3, every time you change your npm version via nvm, you will have to change your script accordingly.

Where is `npm link` registring commands on Ubuntu?

Background
I have an NodeJS oclif CLI named "mydemo" and ran npm link to register and execute the program's commands globally. After I ran npm unlink mydemo to unregister the command, when I type the program's name, I get the error below.
$ mydemo
bash: /home/eric/.nvm/versions/node/v15.8.0/bin/mydemo: No such file or directory
Expected output
$ mydemo
mydemo: command not found
Question
How does Linux still know to look in the ".nvm" directory for this command if I've unlinked it?
Attempts to figure it out
Ran npm unlink
Ran npm uninstall -g mydemo
Ran which mydemo (no output)
Searched for symlinks (maybe I didn't search the right place)
... it still searches that specific ".nvm" directory.
Environment
Ubuntu 20
nvm 0.37.2
node v15.8.0
"#oclif/dev-cli": "^1.26.0"
Nevermind. The command was cached in the shell session, possibly in the $PATH variable. It cleared in a new user session.

PhpStorm 9 env: node: No such file or directory

I am using csscomb to prettify my .scss files. All was fine until I upgraded to PhpStorm 9.
csscomb runs without any problem from the terminal, but PhpStorm seems not to recognize node's path. When I run the command I get:
env: node: No such file or directory
Process finished with exit code 127
Any idea how to configure this ? Tried to edit path manually but failed.
To fix this you need to symlink the nodejs executable to node
sudo ln -s "$(which nodejs)" /usr/local/bin/node
If you installed node with nvm
sudo ln -s "$(which node)" /usr/local/bin/node
Restarting phpstorm fixed the issue. Still wondering why...
because not found nodejs, open & edit the lesscss program code first line, tell him where is the nodejs.

nodeschool cant run lesson from anywhere on terminal

I finished the first lesson for nodeschool
to run the "javascripting" lesson, i just type
$javascripting
on console,
but when installed other lesson "learnyounode"
$sudo npm install --global learnyounode
seems to install ok,
but when i type
$learnyounode
I get,
-bash: learnyounode: command not found
I can see that the module is in /Users/iosdev/npm-global/lib/node_modules
so I how to add this "module" so I can start from anywhere on CLI?
Try adding that path you mentioned to your bash_profile.
cd into your home directory and find this file .bash_profile and look for the line with
export PATH=
and add your path to look like like:
export PATH="/Users/iosdev/npm-global/lib/node_modules:$PATH"
or you just run the above command on your terminal directly.
This will append 'this' path so that bash understands each node module.
Normally your global node modules are installed at /usr/local/bin, and you may see /usr/local/bin already part of the $PATH environment variable.
I installed the module globally as mentioned in your link and i can access it on any directory.

Resources