What is the difference of putting -g in the package installations by npm, webpack, etc ...?

2

For some time now I've installed packages via prompt with npm, bower among other package managers, but I never quite understood what the -g . I know it means global , installing the packages globally on the computer and not just locally in the project specifically. But my doubts are:

  

1 -With the use of -g where are installed packages installed on the computer?

     

2 - If you install for example Vue.js so npm install -g @vue-cli in a project, and in another project using Vue.js install it with the command npm install @vue-cli , where it is searched Vue, from the internet repository or from my computer?

     

3 - If you install Vue.js in a project globally with a particular version and by chance install it again globally with a newer version in another project, the first project that is using the version old may cause problems, the latter overwrites the previous one or two Vue.js are allocated?

    
asked by anonymous 08.09.2018 / 01:07

1 answer

1

The main difference between installing a package globally is that you start executing commands on the command line, according to the [npm doc]) link ):

  

There are two ways to install npm packages: locally or globally. Choose which kind of installation to use based on how you want to use the package.

     

If you want to use a package as a command line tool, then install it globally. This way, it works no matter which directory is current. This is the choice you would use if you were installing grunt, for example.

     

If you want to depend on the package from your own module, then install it locally. This is the choice you would use if you are using require statements, for example.

Translated looks like this:

  

There are two ways to install packages: locally or globally. Choose what kind of installation based on how you want to use the package.

     

If you want to use the package as a command line tool, then install the command globally. This way, the command works regardless of which directory you are in. This is the choice you would have if you were installing grunt, for example.

     

If you want to depend on the package in your own module, then install it locally. This is the choice you would use if you are using require, for example.

  • It depends on the operating system and configuration, but usually the packages are located inside the user's folder.

    • MacOS: / usr / local / lib / node_modules
    • Windows: \ AppData \ Roaming \ npm
  • I did not quite understand the de onde é buscado question. Both npm i commands with or without -g will download the last stable package published in NPM, remembering that the version of the package that will be downloaded may be another depending on your package.json file. Documentation

  • If you install vue globally it will not make any difference because this package must be installed locally (unless you npm link because then it fetches the package globally). Documentation

    • It's okay for you to upgrade vue-cli as it's a development tool.
    • When you talk about installing Vue.js globally, you say install the vue-cli package, right? Cli packages are usually not installed locally because it is a tool to use via command line, according to their documentation :
        

      The CLI (@ vue / cli) is a globally installed npm package and provides the vue command in your terminal. It provides the ability to quickly scaffold a new project via vue create, or prototype new ideas via vue serve. You can also manage your projects using a graphical user interface via vue ui. We will walk through what next in the next few sections of the guide.

  • 08.09.2018 / 03:12