Меню Рубрики

Mac os npm install

Installing Node.js® and NPM on Mac

What’s Node.js® and NPM?

Node.js® is a JavaScript-based environment which you can use to create web-servers and networked applications. You can also use it to perform helpful tasks on your computer such as concatenating and minifying JavaScript files and compiling Sass files into CSS.

NPM is a “package manager” that makes installing Node “packages” fast and easy. A package, also called a module, is just a code library that extends Node by adding useful features. For example, the “request” module simplifies the process of making HTTP requests so you can easily get web resources from other sites.

NPM is installed when you install Node.js®

Although there is a Mac installer program on the Node website, we recommend using Homebrew to install and update Node.

Prerequisites

  • You should have some familiarity with the Mac Terminal application since you’ll need to use it to install and test Node and NPM. You’ll also need the Terminal to use Node.js and NPM. The Terminal application is located in the Utilities folder in the Applications folder.
  • Dependencies. Although you can install Node in other ways, we recommend using Homebrew. Homebrew lets you avoid possible security problems associated with using the sudo command to install software like Node and Node modules.
    • Install Homebrew. Follow the steps on the How to Install Homebrew on a Mac instruction guide to install Homebrew.

Installation Overview

Installing Node.js® and NPM is pretty straightforward using Homebrew. Homebrew handles downloading, unpacking and installing Node and NPM on your system. The whole process (after you have Homebrew installed) should only take you a few minutes.

Installation Steps

  • Open the Terminal app and type brew update . This updates Homebrew with a list of the latest version of Node.
  • **Type brew install node .
  • Sit back and wait. Homebrew has to download some files and install them. But that’s it.

Test it!

Make sure you have Node and NPM installed by running simple commands to see what version of each is installed:

  • Test Node. To see if Node is installed, type node -v in Terminal. This should print the version number so you’ll see something like this v0.10.31 .
  • Test NPM. To see if NPM is installed, type npm -v in Terminal. This should print the version number so you’ll see something like this 1.4.27

How to Update Node and NPM

New versions of Node and NPM come out frequently. You can use Homebrew to update the software it installs.

  1. Make sure Homebrew has the latest version of the Node package. In Terminal type brew update
  2. Upgrade Node: brew upgrade node

How to Uninstall Node and NPM

You can use Homebrew to uninstall packages that it installed:

Источник

Как установить Node.js и NPM в Mac OS

Node JS – популярная платформа Javascript, которая широко используется разработчиками, а npm – это аккомпанирующий её менеджер пакетов. Когда вы установите Node.js, npm установится автоматически. Соответственно, если вам нужен npm, придётся установить и NodeJS.

Есть несколько способов установить Node.js и NPM на Mac, включая использование установщика и использование Homebrew. В данной статье мы расскажем об обоих способах, которые должны работать во всех современных версиях MacOS.

Как установить Node.js и NPM через Homebrew

Самый простой способ установить node.js и npm – через утилиту командной строки Homebrew. Естественно, для этого у вас должен быть установлен менеджер пакетов Homebrew. Кроме того, не помешает обновить программу перед тем, как приступать к инструкции. Выполните следующую команду:

После этого в программе Terminal выполните такую команду, чтобы установить сразу Node.js и npm:

Данный способ самый простой из всех, и с его помощью node.js и npm легко обновлять. Кроме того, удалить их будет так же просто.

Как установить Node.js и NPM через установщик

Если вы по какой-то причине не хотите использовать Homebrew, можете использовать установщик с сайта nodejs.org:

Запустите установщик, как любую другую программу на Mac.

Как узнать, установлены ли NPM и Node.js на Mac

Вы можете узнать, установлены ли node.js и npm на вашем компьютере, использовав следующие команды:

Как проверить работу Node.js

Когда программная платформа node.js будет установлена, вы можете проверить его работу, создав простой сервер. Создайте файл с названием «app.js» со следующим кодом:

Сохраните файл app.js, а затем запустите сервер следующей командой:

Затем откройте браузер и перейдите по этой ссылке:

Вы должны увидеть сообщение « Hello from Node.js».

Это самый простой веб-сервер, созданный с помощью node.js. Вы также можете установить программу Grunt CLI для тестирования node и npm с помощью такой команды:

После этого запустите в командной строке «grunt».

Выше мы рассказали о самых простых способах установить NodeJS и npm на Mac. Надеемся, они вам помогут.

Источник

LearnHow to Install Node.js and NPM on a Mac

Dave McFarland
writes on October 8, 2014

If you’re looking to take your JavaScript coding to another level, Treehouse offers unlimited-access courses in JavaScript (and many other subjects) starting at $25/month. Try our program out with a free seven-day trial today.

How to Install Node.js and NPM on a Mac

JavaScript is one of the most popular programming languages in the world. Because it’s built into most web browsers, programmers and web designers can use JavaScript to add interactive features to websites that reach billions of people. But in the past couple of years, JavaScript has started to play a larger role outside of the browser, due in large part to Node.js.

Node.js is a tool for building fast network applications. It’s known as a “JavaScript runtime environment” which simply means it lets you write JavaScript code that can run on your computer free of any web browser. Node.js is used to create fast web servers by companies like Walmart, eBay and Netflix.

But because Node.js can be used on your desktop computer, programmers have created useful Node-based tools that help with the process of building web sites. For example, Grunt is a popular tool used to automate common tasks like compiling Sass files to CSS, making JavaScript files smaller so they load in less time, and compressing images to smaller file size. While these tools run through the Node.js environment, you’ll use another tool, NPM, to install them. NPM is what’s called a “package manager.” NPM makes installing a tool like Grunt as easy as npm install -g grunt-cli .

But before you can use Node.js or NPM you need to install them — while the NodeJS website includes an installer, there’s a better way to install them on a Mac. In this article, I’ll take you through the process of installing Node.js and NPM on a Mac using Homebrew. In another article, I’ll show you Windows users how to install them on the Windows operating system.

Prerequisites

Before you install Node.js and NPM you’ll first need to have some familiarity with the Mac Terminal application. Terminal lets you dig into the underbelly of the operating system and issue text commands to your computer. You’ll need to use Terminal (or a similar application like iTerm) to not only install Node.js but also to use it and NPM.

Before you can install Node, you’ll need to install two other applications. Fortunately, once you’ve got these on your machine, installing Node takes just a few minutes.

  1. XCode. Apple’s XCode development software is used to build Mac and iOS apps, but it also includes the tools you need to compile software for use on your Mac. XCode is free and you can find it in the Apple App Store.
  2. Homebrew. Homebrew is a package manager for the Mac — it makes installing most open source sofware (like Node) as simple as writing brew install node . You can learn more about Homebrew at the Homebrew website. To install Homebrew just open Terminal and type ruby -e «$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)» . You’ll see messages in the Terminal explaining what you need to do to complete the installation process.

Why Homebrew?

Observant readers will notice in the screenshot above that there’s an installer for NodeJS. You can download it directly from NodeJS.org. I recommend Homebrew over that installer for a few reasons:

  1. When installing Node via the installer, you have to use the sudo command to make sure it installs properly (there is a workaround for this, but it’s complicated). sudo lets the installer place files in areas of your file system that are only accessible to administrators. One nice thing about Homebrew is that it doesn’t require access to administrator-only areas of your computer in order to install NodeJS (or any other package). This is a safer approach as it makes sure that any package you install with Homebrew can’t wreak havoc on your computer.
  2. After installing Node via the installer you have to add the path to the node executable to your system $PATH. This involves mucking around with your shell login file. For experienced Terminal users or Unix-people this isn’t a big deal, but for those new to the command line that step can be daunting. Although the Homebrew method involves installing several different pieces of software, it’s generally just a simple process of point-click-and-wait. It takes a bit longer this way but there’s less room for error.
  3. Homebrew is a great tool for web developers. First, it makes removing Node very easy (otherwise you have to crawl through your file system and delete a bunch of files manually). Second, it greatly simplfies the installation of other useful packages like Git, Ruby, or the very useful wget utility.

Installation

Installing Node.js and NPM is pretty straightforward using Homebrew. Homebrew handles downloading, unpacking and installing Node and NPM on your system. The whole process (after you have XCode and Homebrew installed) should only take you a few minutes.

  1. Open the Terminal app and type brew install node .
  2. Sit back and wait. Homebrew downloads some files and installs them. And that’s it.

To make sure you have Node and NPM installed, run two simple commands to see what version of each is installed:

  • To see if Node is installed, type node -v in Terminal. This should print the version number so you’ll see something like this v0.10.31 .
  • To see if NPM is installed, type npm -v in Terminal. This should print the version number so you’ll see something like this 1.4.27

How to Update Node and NPM

New versions of Node and NPM come out frequently. You can use Homebrew to update the software it installs.

  1. Make sure Homebrew has the latest version of the Node package. In Terminal type brew update
  2. Upgrade Node: brew upgrade node

How to Uninstall Node and NPM

You can use Homebrew to uninstall packages that it installed: brew uninstall node

With Node.js and NPM installed you’ll soon be able to take advantage of the huge world of NPM modules that can help with a wide variety of tasks both on the web server and on your desktop (or laptop) machine. The NPM site lists all of the official Node packages making it easy to make the choice. Have fun and check out my current courses at Treehouse.

100 Responses to “How to Install Node.js and NPM on a Mac”

‘brew install node’ installed node 10.1
‘npm -v’ was 5.6 although 6.01 is the most recent
‘brew upgrade npm’ did not upgrade to latest version of npm
‘npm install -g npm ‘ Will upgrade to the latest version of npm
Hope this helps someone else!

i am getting error when i checking the version npm -v
ERROR: npm is known not to run on Node.js v0.10.40
You’ll need to upgrade to a newer version in order to use this
version of npm. Supported versions are 4, 6, 7, 8, 9. You can find the
latest version at https://nodejs.org/

What confuses me is that I have npm all set up in some projects at work and it works fine. However, I just downloaded a new project and when I run “npm -v” in that project, I get “npm: command not found”. I can’t seem to find any docs on installing node per project. They all seem to be global, including this one.

So how is it npm works in one project but not another? And if there is a way to install it per project, how is that done?

You need node.js and npm installed on your home machine, too. “Command not found” means it’s not installed. Follow the instructions above, and you’ll have everything you need to destroy your free time with work stuff.

You need to install NodeJS globally. NPM comes with it and that is how you’re going to be building your project dependancies. Now if you don’t want to install all those packages that your project requires, then you’re going to want to have your JSON file call them up as devDependancies. Take a look at the link below, it might explain it better than I can.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

  • Mac os no bootable device insert boot disk and press any key
  • Mac os nginx start
  • Mac os nfs manager
  • Mac os network scan
  • Mac os net framework