NPM is incorrect version on latest Ubuntu (18.04) installation











up vote
4
down vote

favorite
2












Normal installation would be sudo apt install nodejs to install Node.js and then sudo apt install npm to install Node Package Manager. However, upon doing so, npm -v says 3.5.2. To upgrade normally, I would do sudo npm install -g npm, which updates to the latest version (which, at the time of writing this article, is 6.0.1).



When I do a which npm, I get /usr/local/bin/npm, however apt installs a symlink at /usr/bin/npm. If I sudo apt purge npm to remove npm, it still leaves the npm version of npm at /usr/local/bin/npm, however npm -v says -bash: /usr/bin/npm: No such file or directory.



Many articles say to use a PPA to install nodejs, but I think there should be a native way to do this through apt.



DigitalOcean instructions on installation normally and through PPA: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04



TecAdmin instructions on installation through PPA: https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/










share|improve this question


























    up vote
    4
    down vote

    favorite
    2












    Normal installation would be sudo apt install nodejs to install Node.js and then sudo apt install npm to install Node Package Manager. However, upon doing so, npm -v says 3.5.2. To upgrade normally, I would do sudo npm install -g npm, which updates to the latest version (which, at the time of writing this article, is 6.0.1).



    When I do a which npm, I get /usr/local/bin/npm, however apt installs a symlink at /usr/bin/npm. If I sudo apt purge npm to remove npm, it still leaves the npm version of npm at /usr/local/bin/npm, however npm -v says -bash: /usr/bin/npm: No such file or directory.



    Many articles say to use a PPA to install nodejs, but I think there should be a native way to do this through apt.



    DigitalOcean instructions on installation normally and through PPA: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04



    TecAdmin instructions on installation through PPA: https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/










    share|improve this question
























      up vote
      4
      down vote

      favorite
      2









      up vote
      4
      down vote

      favorite
      2






      2





      Normal installation would be sudo apt install nodejs to install Node.js and then sudo apt install npm to install Node Package Manager. However, upon doing so, npm -v says 3.5.2. To upgrade normally, I would do sudo npm install -g npm, which updates to the latest version (which, at the time of writing this article, is 6.0.1).



      When I do a which npm, I get /usr/local/bin/npm, however apt installs a symlink at /usr/bin/npm. If I sudo apt purge npm to remove npm, it still leaves the npm version of npm at /usr/local/bin/npm, however npm -v says -bash: /usr/bin/npm: No such file or directory.



      Many articles say to use a PPA to install nodejs, but I think there should be a native way to do this through apt.



      DigitalOcean instructions on installation normally and through PPA: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04



      TecAdmin instructions on installation through PPA: https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/










      share|improve this question













      Normal installation would be sudo apt install nodejs to install Node.js and then sudo apt install npm to install Node Package Manager. However, upon doing so, npm -v says 3.5.2. To upgrade normally, I would do sudo npm install -g npm, which updates to the latest version (which, at the time of writing this article, is 6.0.1).



      When I do a which npm, I get /usr/local/bin/npm, however apt installs a symlink at /usr/bin/npm. If I sudo apt purge npm to remove npm, it still leaves the npm version of npm at /usr/local/bin/npm, however npm -v says -bash: /usr/bin/npm: No such file or directory.



      Many articles say to use a PPA to install nodejs, but I think there should be a native way to do this through apt.



      DigitalOcean instructions on installation normally and through PPA: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04



      TecAdmin instructions on installation through PPA: https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/







      apt package-management software-installation nodejs npm






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 14 at 21:14









      Blairg23

      194112




      194112






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          The way I found is to purge npm through sudo apt purge npm, then simply recreate a symlink to the global installation via ln -s /usr/local/bin/npm /usr/bin/npm. After that fix, npm -v returns 6.0.1 as expected.






          share|improve this answer

















          • 2




            Worked with Ubuntu 18.04 running through UserLAnd on Android 6.0.1. Thank you! :)
            – l3l_aze
            Aug 26 at 8:58






          • 1




            OP you should mark this as the answer.
            – Robert Munn
            Dec 2 at 17:07


















          up vote
          1
          down vote













          To have control on installed npm version, I always use nvm (node version control). You can install it through the instructions here: https://github.com/creationix/nvm
          Then by following command install the latest npm on your computer:



          nvm install node






          share|improve this answer




























            up vote
            1
            down vote













            TLDR: This problem is caused by Bash caching the path of the npm command, and can be solved by hash -d npm. You don't even need to deal with apt purge unless you want to.



            Explanation



            Here were my steps for getting a new npm version on Ubuntu. First, do the installation as OP describes:



            $ sudo apt-get install npm
            (...apt installation of npm was successful...)
            $ npm -v
            3.5.2
            $ command -v npm
            /usr/bin/npm
            $ sudo npm install -g npm
            (...npm installation of npm was successful...so far, so good)


            You can see that the new version is already working fine in /usr/local/bin/npm, but unfortunately the Bash cache still has /usr/bin/npm:



            $ /usr/local/bin/npm -v
            6.4.1
            $ npm -v
            3.5.2
            $ command -v npm
            /usr/bin/npm
            $ type npm
            npm is hashed (/usr/bin/npm)


            To fix the problem, clear it from the Bash cache (do this in all open shells):



            $ hash -d npm


            Now the new version works as desired:



            $ npm -v
            6.4.1
            $ command -v npm
            /usr/local/bin/npm





            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036278%2fnpm-is-incorrect-version-on-latest-ubuntu-18-04-installation%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              7
              down vote



              accepted










              The way I found is to purge npm through sudo apt purge npm, then simply recreate a symlink to the global installation via ln -s /usr/local/bin/npm /usr/bin/npm. After that fix, npm -v returns 6.0.1 as expected.






              share|improve this answer

















              • 2




                Worked with Ubuntu 18.04 running through UserLAnd on Android 6.0.1. Thank you! :)
                – l3l_aze
                Aug 26 at 8:58






              • 1




                OP you should mark this as the answer.
                – Robert Munn
                Dec 2 at 17:07















              up vote
              7
              down vote



              accepted










              The way I found is to purge npm through sudo apt purge npm, then simply recreate a symlink to the global installation via ln -s /usr/local/bin/npm /usr/bin/npm. After that fix, npm -v returns 6.0.1 as expected.






              share|improve this answer

















              • 2




                Worked with Ubuntu 18.04 running through UserLAnd on Android 6.0.1. Thank you! :)
                – l3l_aze
                Aug 26 at 8:58






              • 1




                OP you should mark this as the answer.
                – Robert Munn
                Dec 2 at 17:07













              up vote
              7
              down vote



              accepted







              up vote
              7
              down vote



              accepted






              The way I found is to purge npm through sudo apt purge npm, then simply recreate a symlink to the global installation via ln -s /usr/local/bin/npm /usr/bin/npm. After that fix, npm -v returns 6.0.1 as expected.






              share|improve this answer












              The way I found is to purge npm through sudo apt purge npm, then simply recreate a symlink to the global installation via ln -s /usr/local/bin/npm /usr/bin/npm. After that fix, npm -v returns 6.0.1 as expected.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 14 at 21:14









              Blairg23

              194112




              194112








              • 2




                Worked with Ubuntu 18.04 running through UserLAnd on Android 6.0.1. Thank you! :)
                – l3l_aze
                Aug 26 at 8:58






              • 1




                OP you should mark this as the answer.
                – Robert Munn
                Dec 2 at 17:07














              • 2




                Worked with Ubuntu 18.04 running through UserLAnd on Android 6.0.1. Thank you! :)
                – l3l_aze
                Aug 26 at 8:58






              • 1




                OP you should mark this as the answer.
                – Robert Munn
                Dec 2 at 17:07








              2




              2




              Worked with Ubuntu 18.04 running through UserLAnd on Android 6.0.1. Thank you! :)
              – l3l_aze
              Aug 26 at 8:58




              Worked with Ubuntu 18.04 running through UserLAnd on Android 6.0.1. Thank you! :)
              – l3l_aze
              Aug 26 at 8:58




              1




              1




              OP you should mark this as the answer.
              – Robert Munn
              Dec 2 at 17:07




              OP you should mark this as the answer.
              – Robert Munn
              Dec 2 at 17:07












              up vote
              1
              down vote













              To have control on installed npm version, I always use nvm (node version control). You can install it through the instructions here: https://github.com/creationix/nvm
              Then by following command install the latest npm on your computer:



              nvm install node






              share|improve this answer

























                up vote
                1
                down vote













                To have control on installed npm version, I always use nvm (node version control). You can install it through the instructions here: https://github.com/creationix/nvm
                Then by following command install the latest npm on your computer:



                nvm install node






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  To have control on installed npm version, I always use nvm (node version control). You can install it through the instructions here: https://github.com/creationix/nvm
                  Then by following command install the latest npm on your computer:



                  nvm install node






                  share|improve this answer












                  To have control on installed npm version, I always use nvm (node version control). You can install it through the instructions here: https://github.com/creationix/nvm
                  Then by following command install the latest npm on your computer:



                  nvm install node







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 3 at 23:01









                  Farzad

                  212




                  212






















                      up vote
                      1
                      down vote













                      TLDR: This problem is caused by Bash caching the path of the npm command, and can be solved by hash -d npm. You don't even need to deal with apt purge unless you want to.



                      Explanation



                      Here were my steps for getting a new npm version on Ubuntu. First, do the installation as OP describes:



                      $ sudo apt-get install npm
                      (...apt installation of npm was successful...)
                      $ npm -v
                      3.5.2
                      $ command -v npm
                      /usr/bin/npm
                      $ sudo npm install -g npm
                      (...npm installation of npm was successful...so far, so good)


                      You can see that the new version is already working fine in /usr/local/bin/npm, but unfortunately the Bash cache still has /usr/bin/npm:



                      $ /usr/local/bin/npm -v
                      6.4.1
                      $ npm -v
                      3.5.2
                      $ command -v npm
                      /usr/bin/npm
                      $ type npm
                      npm is hashed (/usr/bin/npm)


                      To fix the problem, clear it from the Bash cache (do this in all open shells):



                      $ hash -d npm


                      Now the new version works as desired:



                      $ npm -v
                      6.4.1
                      $ command -v npm
                      /usr/local/bin/npm





                      share|improve this answer



























                        up vote
                        1
                        down vote













                        TLDR: This problem is caused by Bash caching the path of the npm command, and can be solved by hash -d npm. You don't even need to deal with apt purge unless you want to.



                        Explanation



                        Here were my steps for getting a new npm version on Ubuntu. First, do the installation as OP describes:



                        $ sudo apt-get install npm
                        (...apt installation of npm was successful...)
                        $ npm -v
                        3.5.2
                        $ command -v npm
                        /usr/bin/npm
                        $ sudo npm install -g npm
                        (...npm installation of npm was successful...so far, so good)


                        You can see that the new version is already working fine in /usr/local/bin/npm, but unfortunately the Bash cache still has /usr/bin/npm:



                        $ /usr/local/bin/npm -v
                        6.4.1
                        $ npm -v
                        3.5.2
                        $ command -v npm
                        /usr/bin/npm
                        $ type npm
                        npm is hashed (/usr/bin/npm)


                        To fix the problem, clear it from the Bash cache (do this in all open shells):



                        $ hash -d npm


                        Now the new version works as desired:



                        $ npm -v
                        6.4.1
                        $ command -v npm
                        /usr/local/bin/npm





                        share|improve this answer

























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          TLDR: This problem is caused by Bash caching the path of the npm command, and can be solved by hash -d npm. You don't even need to deal with apt purge unless you want to.



                          Explanation



                          Here were my steps for getting a new npm version on Ubuntu. First, do the installation as OP describes:



                          $ sudo apt-get install npm
                          (...apt installation of npm was successful...)
                          $ npm -v
                          3.5.2
                          $ command -v npm
                          /usr/bin/npm
                          $ sudo npm install -g npm
                          (...npm installation of npm was successful...so far, so good)


                          You can see that the new version is already working fine in /usr/local/bin/npm, but unfortunately the Bash cache still has /usr/bin/npm:



                          $ /usr/local/bin/npm -v
                          6.4.1
                          $ npm -v
                          3.5.2
                          $ command -v npm
                          /usr/bin/npm
                          $ type npm
                          npm is hashed (/usr/bin/npm)


                          To fix the problem, clear it from the Bash cache (do this in all open shells):



                          $ hash -d npm


                          Now the new version works as desired:



                          $ npm -v
                          6.4.1
                          $ command -v npm
                          /usr/local/bin/npm





                          share|improve this answer














                          TLDR: This problem is caused by Bash caching the path of the npm command, and can be solved by hash -d npm. You don't even need to deal with apt purge unless you want to.



                          Explanation



                          Here were my steps for getting a new npm version on Ubuntu. First, do the installation as OP describes:



                          $ sudo apt-get install npm
                          (...apt installation of npm was successful...)
                          $ npm -v
                          3.5.2
                          $ command -v npm
                          /usr/bin/npm
                          $ sudo npm install -g npm
                          (...npm installation of npm was successful...so far, so good)


                          You can see that the new version is already working fine in /usr/local/bin/npm, but unfortunately the Bash cache still has /usr/bin/npm:



                          $ /usr/local/bin/npm -v
                          6.4.1
                          $ npm -v
                          3.5.2
                          $ command -v npm
                          /usr/bin/npm
                          $ type npm
                          npm is hashed (/usr/bin/npm)


                          To fix the problem, clear it from the Bash cache (do this in all open shells):



                          $ hash -d npm


                          Now the new version works as desired:



                          $ npm -v
                          6.4.1
                          $ command -v npm
                          /usr/local/bin/npm






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 3 at 23:38

























                          answered Dec 3 at 22:47









                          krubo

                          23715




                          23715






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036278%2fnpm-is-incorrect-version-on-latest-ubuntu-18-04-installation%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                               ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕