Workers: Wrangler npm install error EACCES as root

I am trying to install Wrangler CLI for cloudflare into an Ubuntu 19.10 Desktop VM. No matter what I do, I am getting an EACCES error, which is weird, because I opened a root shell using sudo -s before running npm:

npm i -g @cloudflare/wrangler

/usr/local/bin/wrangler -> /usr/local/lib/node_modules/@cloudflare/wrangler/run-wrangler.js

@cloudflare/[email protected] postinstall /usr/local/lib/node_modules/@cloudflare/wrangler
node install-wrangler.js

throw err;

Error: EACCES: permission denied, mkdir ‘/root/.wrangler’
at mkdirSync (fs.js:753:3)
at Object. (/usr/local/lib/node_modules/@cloudflare/wrangler/install-wrangler.js:57:3)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
npm ERR! errno 1
npm ERR! @cloudflare/[email protected] postinstall: node install-wrangler.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @cloudflare/[email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-01-04T16_04_25_890Z-debug.log

First, I tried using the version of npm and nodejs provided by Ubuntu:

$ sudo apt install npm

Then, when it failed, I tried updating npm:

npm i -g [email protected]

After that updated, I exited my terminal completely, then opened a new term window, sudo -s to become root, and verified that npm was updated by using:

npm --version


Still, the same error.

Then, after reviewing install docs for Wrangler, I saw that they suggested uninstalling the version packaged by the distro, and using a node version manager to install node + npm, then updating npm, then installing.

So, I uninstalled npm and node using apt, then downloaded nvm, ran it to install the latest nodejs + npm, and tried the Wrangler install again, but I keep getting the same EACCES error, even though I’m running as root.

Can anyone help?

If you run mkdir /root/.wrangler yourself in the root shell, does it work? Maybe try running it again afterwards if so, and/or chmod 600 /root/.wrangler.

If it still persists i’d recommend using rust/cargo to install instead since that’s the language the tool is actually written in.

Thanks for the response. I tried manually creating that dir, but it still gives me the error. :frowning:

Try this:

$ sudo su -
# npm i @cloudflare/wrangler -g
# exit
$ mkdir ~/.wrangler
$ npm i @cloudflare/wrangler -g
1 Like

I was able to successfully install it by temporarily changing the /root permissions to everyone. If you already tried to create a /root/.wrangler directory you will have to temporarily change those permissions too.

stat /root # should be 700
sudo chmod 777 /root
# sudo chmod 777 /root/.wrangler
sudo npm install -g @cloudflare/wrangler
sudo chmod 700 /root
sudo chmod -R 700 /root/.wrangler
wrangler --help
1 Like