Global ionic command not recognized after switching Node version

Weird issue with ionic CLI after switching Node versions

I’m having a strange problem with the ionic command line tool. Here’s what’s happening:

$ node -v
v0.12.9

$ ionic -v
2.0.0-beta.37

$ nvm use 4.4.7
now using node v4.4.7

$ ionic -v
-bash: ionic: command not found

I’ve got ionic installed globally, but when I switch to a different Node version using nvm, the terminal can’t find the ionic command anymore.

Does anyone know why this is happening? I thought global packages should work across different Node versions. Is there something I’m missing about how nvm and global packages interact?

Any help would be appreciated. Thanks!

yea, i had this prob too. its annoying but easy fix. when u switch node versions, the global packages dont come with. just reinstall ionic for each version u wanna use it with:

nvm use 4.4.7
npm install -g ionic

should work after that. gl mate!

This is a common issue when using nvm to manage Node versions. The global packages are installed separately for each Node version. To resolve this, you’ll need to reinstall ionic for each Node version you intend to use.

After switching to your desired Node version with nvm, run:

npm install -g ionic

This will install ionic globally for that specific Node version. You may need to repeat this process for other versions you frequently use.

Alternatively, consider using a tool like ‘n’ instead of nvm. It handles global packages differently and might prevent this issue. However, switching tools has its own challenges, so weigh the pros and cons before making a change.

I’ve run into this exact issue before, and it can be pretty frustrating. The problem stems from how nvm manages different Node versions and their associated global packages.

When you switch Node versions with nvm, it creates a separate directory for each version’s global packages. So, your ionic CLI installed under v0.12.9 isn’t accessible when you switch to v4.4.7.

The solution is to reinstall ionic globally after switching Node versions. Try this:

nvm use 4.4.7
npm install -g ionic

This should make ionic available again. You’ll need to do this for each Node version you want to use ionic with.

Alternatively, you could look into using ‘nvm-windows’ if you’re on Windows, which might handle the global packages differently.