Dawit Mesfin
Dawit Mesfin

Reputation: 375

What is "installing packages globally or locally" in react js mean?

I have started learning react js recently, when I try to setting up the environment I am confused with a word,installing packages globally and locally. What does globally and locally mean here?

Upvotes: 3

Views: 12471

Answers (2)

tscrip
tscrip

Reputation: 140

Installing packages Global will make it available anywhere on your system. For example, with create-react-app, you can run that in C:\ or in C:\Users\dmesfin\ and and the command will run in both locations. To install a package globally, you will just do npm install -g create-react-app

Installing packages locally only allows them to be run inside you project folder. For example, if you were to do create-react-app test-project this would create a react project with a package.json. To install a package, you would simply run npm install antd and that package would be installed into your project and it would be visible in your package.json.

Generally, you want to install your generators like create-react-app or other CLI tools globally because they are not going to change that much and you are only going to use it once to bootstrap your project. For libraries you may use inside your project (like react or react-router), you would want to install those locally because they may change, and you may have two projects going that use two different versions.

Upvotes: 2

Noman Gul
Noman Gul

Reputation: 397

this concept is primarily related to the node/npm ecosystem.

The main difference between local and global packages is this:

  • local packages are installed in the directory where you run npm install <package-name>, and they are put in the node_modules folder under this directory
  • global packages are all put in a single place in your system (exactly where depends on your setup), regardless of where you run npm install -g <package-name>

In your case, you may want to install create-react-app package. You should install it globally in order to create a react project anywhere inside your system.

npm i -g create-react-app

Upvotes: 6

Related Questions