I'm not looking for solution (ok, it would be handy too) but mostly for explanation why it works that way in Linux.
OS: Ubuntu 22.04.1 (ubuntu-22.04.1-desktop-amd64.iso)
Node.js: installed through NVM, v16.18.0
I have simple shell script:
test.sh
node --eval "console.log(123)"
sleep 2
and if I run it through terminal that way:
- Click mouse right button on background in script directory in Nautilius or Nemo
- Click on
open terminal here
- We are in terminal in folder of shell script. Now type command
./test.sh
and hit enter
then everything works fine, node is called, we see 123
as output and after 2 seconds shell script is finished because of sleep command after node calling.
The most surprising part (for me I guess) is when I'd like to run that shell script directly from FileManager (system default Nautilius or installed Nemo) that way:
- click right on
test.sh
file and click on Run as a Program
The result of it is terminal shows up with error in it: "node: not found"
and after 2 seconds it closes because of sleep
command.
Why there is a difference? In first try, terminal sees node.js, in second try terminal doesn't see it. And besides, how to fix it?
EDIT:
I've found some, I've installed NVM through terminal before along with one of node.js version. But now I've additionally installed Node.js through GUI (Ubuntu Software) and now both ways works. Why?
Why installing something in terminal doesn't make it work in both cases?