Cant install PM2 globally due to "Missing Permissions"

Hey there Glitch community, so im trying to install the PM2 npm module (https://www.npmjs.com/package/pm2) using the command npm install -g pm2 on the Glitch Terminal but I get this awkward permission error and the installation fails, how could I fix this or is this an issue on your guys end? Thanks.

Hi @CheatTriggers,

The following steps will allow you to install global packages in your assigned Glitch instance:

  1. Create a directory for global packages
$ mkdir "${HOME}/.npm-packages"
  1. To let know npm to use the directory, add this in ~/.npmrc (you can use $ vi ~/.npmrc)
prefix=${HOME}/.npm-packages
  1. The create and modify the file under ~/.bashrc and add the following content
NPM_PACKAGES="${HOME}/.npm-packages"

PATH="$NPM_PACKAGES/bin:$PATH"

# Unset manpath so we can inherit from /etc/manpath via the `manpath` command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
export MANPATH="$NPM_PACKAGES/share/man:$(manpath)"

After that, load ~/.bashrc into the terminal

source ~/.bashrc

That’s it. Now you will be able to install global packages. I tested with pm2 and I was able to install and call the package after installation.

7 Likes

Thanks it worked perfectly! :smiley:

Hello,

actually the easiest way to install “global” packages is to put them in package.json. They will immediately be available in the terminal and in the project.

This problem has crept back up again. I was able to solve it with the .npm-packages trick… but that’s not an awesome long-term solution.

Do you folks intend to restore the earlier functionality?

Does adding them to your package.json file as suggested above not work for you?

Nah. I tried both methods. It installed it locally, but not globally.

And what’s the difference? Glitch adds the local binaries to your path, so it should work exactly the same

That’s the issue. I’m getting a permission denied error.

See this screencast of the error:

Sure, the suggestion though was to add it to your package.json file, which seems to work without issue - see https://glitch.com/edit/#!/scythe-impulse for example. If you remix it, you can run firebase from the console.

I tried adding it via package.json earlier, but it added it locally, not globally.

I just tried to reproduce it as a screencast, but the button to open the console is gone now :frowning:

Is there something that I need to do to enable that console button under advanced options, or is it just down for maintenance?

In Glitch, there is no difference between “locally” and “globally”. You can install it “locally” and you get it everywhere.

Can you please try what we are suggesting? You’ll see that it will work exactly as you want. If it doesn’t, describe exactly what is missing. Thanks :slight_smile:

I will try it and send you a screencast. For some reason I can’t get to the console right now. the “OPEN CONSOLE” button is missing. I’ll keep trying to break into the console :slight_smile:

Well now it works. Sorry for the false alarm. I tried all install options this morning, and none of them work. Now it’s working just fine!

Awesome :slight_smile: The console is in Project Menu -> Advanced Options -> Open Console

Actually it just moved - it’s under the logs panel now!

1 Like