Tag: cordova

How to install Ionic without using sudo on macOS

The first step for using any tool or platform is installing it.
As a user who had many problems using sudo, I tried to find a way to install ionic without it, found many over the internet but i’ll only list the two that i have tried

The lazy way

1- Install Node Version Manger ( nvm )  use the install script using curl:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

the current version of nvm as of today is v0.33.2 , so make sure to verify that you have installed the latest version by executing the following command

nvm --version

But always refer to github to check what is the latest version

2- Install the latest version of nodejs

nvm install node

Make sure that you are using the installed nodejs version by using the following comand

nvm use node

For more information about using nvm visit this link

3- Now you are ready to install cordova and ionic without sudo

npm install -g cordova ionic

By using nvm you are installing nodejs in your user home directory, I find this way simple and easy .The best thing though is that you can have as many node versions as you need on your user account, and no fear that another user would break your work if he upgraded nodejs installed globally on the system .

you can switch between the installed versions easily read the nvm documentation for more information.


The Long way

1- Make a directory for global installations

mkdir ~/.npm-global

2- Create a new file  called .npmrc

touch ~/.npmrc

3- Add the following line to the created file

prefix = ~/.npm-global

4- Depending on the shell you are using add the following line to .bashrc  or  .zshrc

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

5- Source your   .zshrc  or   .bashrc

source ~/.bashrc  or   source ~/.zshrc

6- Install HomeBrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

7- Instal the latest nodejs

brew install node

8- now you can install cordova and ionic without sudo

npm install -g cordova ionic

This way is long and a bit complicated as you can see, especially if you don’t like messing around with your system files, but still worth it.

and here you go choose the one you like, try it and let me know if you face any issues..


Filed under: Learning, Programming, TechTagged with: , ,