1

I’m using Amazon Linux and node version 5.10.0. I want to install a module globally, so that I can run node scripts from different directories for different users. So I tried the below …

[davea@mydevbox ~]$ sudo npm install -g selenium-webdriver
/usr/lib
└─┬ selenium-webdriver@2.53.1 
  ├── adm-zip@0.4.4 
  ├─┬ rimraf@2.5.2 
  │ └─┬ glob@7.0.3 
  │   ├─┬ inflight@1.0.4 
  │   │ └── wrappy@1.0.1 
  │   ├── inherits@2.0.1 
  │   ├─┬ minimatch@3.0.0 
  │   │ └─┬ brace-expansion@1.1.3 
  │   │   ├── balanced-match@0.3.0 
  │   │   └── concat-map@0.0.1 
  │   ├── once@1.3.3 
  │   └── path-is-absolute@1.0.0 
  ├── tmp@0.0.24 
  ├─┬ ws@1.1.0 
  │ ├── options@0.0.6 
  │ └── ultron@1.0.2 
  └─┬ xml2js@0.4.4 
    ├── sax@0.6.1 
    └── xmlbuilder@8.2.2 

I received no errors, and so assumed all was well. But then when I logged in as a different user, and tried to run a script, I get this error complaining about missing the module I just installed …

[davea@mydevbox ~]$ sudo su - jboss
Last login: Tue Apr 26 15:13:47 UTC 2016 on pts/0
[jboss@mydevbox ~]$ cd .jenkins/jobs/subco/workspace/
[jboss@mydevbox workspace]$ cd automated-tests/
[jboss@mydevbox automated-tests]$ cd nodejs/
[jboss@mydevbox nodejs]$ sh run_test.sh 
(EE) 
Fatal server error:
(EE) Server is already active for display 0
    If this server is no longer running, remove /tmp/.X0-lock
    and start again.
(EE) 
Validation Complete
module.js:341
    throw err;
    ^

Error: Cannot find module 'selenium-webdriver'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/home/jboss/.jenkins/jobs/subco/workspace/automated-tests/nodejs/js/Optimus.js:2:17)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)

How do I install a module globally so that it is visible to everyone?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • what does `npm root -g` give you when you are logged in as the other user? (http://stackoverflow.com/a/24295332/387573) – crackmigg Apr 26 '16 at 16:12
  • When I run that command I get "/usr/local/lib/node_modules". I'm reading the thread you posted but I'm still unclear what configuration changes I need to make to get things working right. – Dave Apr 26 '16 at 16:38
  • And when you run it as davea you get `/usr/lib/node_modules`? Then you should try to change the global prefix with `npm config --global set prefix` or with an `.npmrc` file. See http://stackoverflow.com/q/19874582/387573 – crackmigg Apr 26 '16 at 18:22
  • Yes, davea is set to /usr/local/lib/node_modules. As davea, I ran "sudo npm config --global set prefix /usr/local/lib/node_modules". But then when I ran "sudo npm install selenium-webdriver", the node_modules just got created in the directory from which I ran that command, so it is still not installing it in a place that is accessible to all users. – Dave Apr 27 '16 at 19:31

0 Answers0