31

I want to start using the ionic framework, but unfortunately I'm already failing on the first step.

I am running Ubuntu 13.04 and I have node v0.10.25 installed. I've installed ionic, at described in their docs:

sudo npm install -g cordova
sudo npm install -g ionic

The installation went well, no errors or warnings, but after the installation I type

ionic

and I get the error:

No command 'ionic' found, did you mean:
 Command 'ionice' from package 'util-linux' (main)
 Command 'sonic' from package 'sonic' (universe)
ionic: command not found

I'm pretty new to ubuntu so I might have something not configured correctly, but I can't find what.

Thanks

1
  • 1
    Couple of questions. Are you using bash or some other linux shell? Can you run: npm list -g --depth=0 to see if the ionic module is listed and if so, post the path? Most likely the place where the ionic binary is not in your PATH environment variable.
    – JimTheDev
    Aug 5, 2014 at 3:08

13 Answers 13

55

for some of you, the two answer above might not work. here's a more general solution for situation where you see "XX" command not found

first check your npm root and npm root -g the result for the npm root -g should be something like "/usr/local". if it's not, then you found your problem.

change it by:

npm config set prefix /usr/local

then npm root -g should give you something like /usr/local/lib/node_modules . Then go ahead re-install everything with -g you will be good to go!

6
  • 2
    If you followed the instructions here to "fix your npm permissions" and setup a different folder (one your user actually owns) to save the global libs to. You might want you global lib directory somewhere else then /usr/local.
    – Oli
    Mar 15, 2016 at 20:06
  • 1
    I added an answer with more details and instructions how to make it work here
    – Oli
    Mar 15, 2016 at 20:32
  • 1
    aww yeah, first real contribution to the stackoverflow Jul 22, 2016 at 2:40
  • Wow, thanks for the answer, that is unique solution for me Jan 20, 2020 at 17:10
  • 1
    you broke my npm Mar 2, 2020 at 6:56
28

Well, I found it finally.

The ionic installation was at /home/guy/npm/bin/ionic, not at /usr/bin/ionic at it should be.

Solved it with:

sudo ln -s /home/guy/npm/bin/ionic /usr/bin/ionic
3
  • For me it was at /Users/myusername/.node/lib/node_modules/ionic/bin/ionic
    – Bryan
    Oct 31, 2015 at 1:32
  • this would not work for some people's mac. urs has special permission policy. npm config set prefix /usr/local Jan 3, 2016 at 16:22
  • I did find my ionic file inside /usr/local/lib/node_modules/ionic/bin/ionic and deleted the file inside /usr/bin/ionic to run your command. The problem was not solved. I fixed the problem by using every ionic command with sudo ionic. I think that I will figure out the problem soon, but it may be connected with the $PATH Variable. I do not have npm in my path variable. Apr 17, 2017 at 10:21
21

I solved the problem by cd to my root. Then install ionic as root admin.

$ sudo npm install -g cordova ionic

then run

$ ionic

to see if it's working.

4
  • You might not want to install ionic using root permissions, as the downloaded stuff will be owned by root, which can cause problems using ionic later, instead you should do what the official docs say, and make yourself the owner of your global lib directory of npm: docs.npmjs.com/getting-started/fixing-npm-permissions
    – Oli
    Mar 15, 2016 at 20:02
  • I added an answer with more details here
    – Oli
    Mar 15, 2016 at 20:31
  • Worked for me. Great!.
    – Raghav
    Mar 24, 2018 at 7:34
  • I've been trying to fix it for hours. This worked!
    – joeyk16
    Oct 21, 2021 at 5:07
10

Someone might run into this after trying to change the global library directory of npm to a folder they have permissions to write to in order to be able to install global libs without root permissions.

In that case you might have forgotten to add the new folder to you PATH environment variable.

The whole process of fixing Permissions can be found here.

in case that source disappears here is a copy of the steps:

There are times when you do not want to change ownership of the default directory that npm uses (i.e. /usr) as this could cause some problems, for example if you are sharing the system with other users.

Instead, you can configure npm to use a different directory altogether. In our case, this will be a hidden directory in our home folder.

  1. Make a directory for global installations:

    mkdir ~/.npm-global

  2. Configure npm to use the new directory path:

    npm config set prefix '~/.npm-global'

  3. Open or create a ~/.profile file and add this line:

    export PATH=~/.npm-global/bin:$PATH

  4. Back on the command line, update your system variables:

    source ~/.profile

Test: Download a package globally without using sudo. npm install -g jshint

Instead of steps 2-4 you can also use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):

NPM_CONFIG_PREFIX=~/.npm-global npm install -g jshint

if you just follow these steps and reinstall all the Global libs there is a good chance that it will start working for you anyways...

Just remember that if you do this, you will save your global libs into the folder created in step 1 instead of the default location in /usr/local or just /usr (depending on your OS flavor i guess?)

0
9

First Solution

I recently ran into this issue and the only solution that worked for me was to uninstall both ionic and cordova.

npm uninstall -g cordova
npm uninstall -g ionic

Then just reinstall

npm install -g cordova
npm install -g ionic 

Second Solution

I ran into this issue again! This time check your environmental variables.

Run npm bin -g and check if the path returned is in your environmental variables. For me, it prompted that it was not found in the terminal output. I added that path to the environmental variables and restarted the terminal. From there everything started to work again. (source)

1
  • 1
    Running 'npm bin -g' then setting the 'export PATH="/usr/local/Cellar/node/11.7.0/bin"' to the correct path did it for me. Thanks! Jan 11, 2020 at 21:38
4

I had the same problem with “bash: ionic: command not found”, then I added:

%USERPROFILE%\AppData\Roaming\npm

to my environment variable’s path, then I reinstalled ionic and cordova and it start working.

3

For Mac users

1. install the ionic

npm i -g @ionic/cli

2. check npm path

npm root -g

3. copy full path of ionic

Ex. /usr/local/Cellar/node/15.2.1/lib/node_modules/@ionic/cli/bin

4. open this file as administrator "/etc/paths" with nano or whatever editor

Ex. sudo nano /etc/paths

5. Add ionic bin file full path to file ends. And save file.

That's it.

2

Run npm root -g, copy the result path and add it to the paths file:

sudo nano /etc/paths

Restart your console and it will work.

1

this worked for me. try adding below to the ~/.bash_profile for mac OSX el capitan users:

NPM_PACKAGES="${HOME}/.npm-packages"

NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"

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
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"

then run source ~/.bash_profile to reload the profile in terminal.

additional info: node v4.3.1

1

In my case, I have just uninstalled ionic and then reinstalled it. And it is working fine now.

1

I also faced same problem but i solved i used following commands on terminal it worked

  • sudo npm uninstall ionic

    then  i used
    

sudo npm install -g cordova ionic@latest

and it worked fine it automatically installs best stabel version of cordova and latest stable version of ionic . for me it installed ionic 3.7.0 and cordova 7.0.1

1

you can change temporary : npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2

  • change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm\node_modules2

  • Run your command to install your package .

  • open file explorer copy the link C:\Users[username]\AppData\Roaming\npm\node_modules

    ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.

  • copy your package file CMD to parent folder "npm"

  • copy your package folder to parent folder "node_modules"

  • now run npm config set prefix C:\Users[username]\AppData\Roaming\npm

  • change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm

  • now package working correctly with Command line

=> this method working with me When npm block in installation Package for IONIC installation and ReactNative and another package npm.

0

The package name has changed from ionic to @ionic/cli! To update, run: npm uninstall -g ionic Then run: npm i -g @ionic/cli

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.