- Installing nodejs on macOS Apple Silicon (M1)
- Share on
- You may also enjoy
- Display latest blog posts on GitHub profile readme
- July 19, 2020
- Kotlin Type Aliases
- June 27, 2020
- Introduction to Kotlin (Part 3): classes, properties, objects, and interfaces
- June 12, 2020
- Introduction to Kotlin (Part 2): if, when, and looping
- May 25, 2020
- Install Node on M1 Mac
- 6 Answers 6
- From node v16.x:
- From node v15.x:
- Apple Silicon Support #37309
- Comments
- AshCripps commented Feb 10, 2021 •
- How to run Node.js on Apple Silicon currently
- Current Known Bugs
- To Do List
- AshCripps commented Feb 25, 2021
- targos commented Mar 10, 2021 •
- AshCripps commented Mar 10, 2021
- AshCripps commented Mar 10, 2021
- AshCripps commented Mar 18, 2021
- rvagg commented Mar 19, 2021
- macOS Big Sur: How to setup Node.js on Apple M1 Machine
- About the author
- Step 0. Remove x86 zsh binary
- Step 1. Install Apple Silicon version of the Homebrew
- Step 2. Install node and yarn
- Step 3. Install packages to run Gatsby
- So, how much faster is ARM Node compared to x86
Installing nodejs on macOS Apple Silicon (M1)
I recently bought a new MacBook Pro with the M1 Apple Silicon CPU. While most things seem to be working great, some developer tools are not yet distributed as native aarch64 binaries. Currently, nodejs is one of those tools. The developers are working on official support, but it isn’t available yet. Fortunately thanks to the nvm project it is still easy to get up and running.
First, if you do not already have the xcode command line tools installed you should install them. This will download the needed C++ compiler and other development tools. Do this by running:
Once that completes, install nvm per their instructions. The command will look something like the following (to ensure you get the latest version of nvm use the command from Github).
Note that if you do not already have a profile file (
/.bashrc) for your shell it won’t be able to install correctly. You should create the appropriate file(s) first before running the command below.
Now that you have nvm installed you can run the following command to install node. Version 15 is the one that currently (Jan 2021) works on aarch64 for Mac.
If everything works correctly this step will take a while to compile everything and copy the newly buily node to the correct install location inside the
/.nvm directory. After the build and install completes test the install by running:
You will probably need to close and re-open your terminal for the command to be found.
Finally, you will want to clear the nvm cache to reduce clutter. After the build mine was consuming about 11GB, vs about 100MB once the cache was cleared. This can be done using:
Hopefully, this helps someone else that is also on the bleeding edge of Apple hardware!
This article is also published on dev.to.
Updated: January 19, 2021
Share on
You may also enjoy
Display latest blog posts on GitHub profile readme
July 19, 2020
Recently GitHub updated the user profile page to allow custom user-defined content to be displayed. This is done via a profile README.
Kotlin Type Aliases
June 27, 2020
Something I recently learned about in Kotlin, that I do not see talked about very often, are type aliases. Type aliases allow for custom names to be specifi.
Introduction to Kotlin (Part 3): classes, properties, objects, and interfaces
June 12, 2020
In part one of this series we talked about variables, types, and functions, and in part two we covered conditionals and looping. In part three we will now t.
Introduction to Kotlin (Part 2): if, when, and looping
May 25, 2020
In part one of this Introduction to Kotlin series, we talked about what Kotlin is and about some of the basics of the language (variables, types, and functio.
Источник
Install Node on M1 Mac
Kind of a noob here on questions about binaries, processors and how that all works together:
I have a new Mac with an M1 chip, and want to install Node. I’m used to do this with Homebrew. Now, if I install Homebrew, I’m strongly recommended to use Rosetta, so I did. Next step: installing Node. So instead of brew install node I do arch -x86_64 brew install node .
This works fine, only I’m wondering, am I now using node in a sub-optimal way? Is Node also using Rosetta, instead of directly running on the M1 chip?
6 Answers 6
I just got my M1 Mac mini. I did add an alias since I use oh-my-zsh to my
/.zshrc for alias brew=’arch -x86_64 brew so I don’t have to keep typing all that. I brew install nvm then nvm ls-remote and installed v15.5.0. It gets built DV8_TARGET_ARCH_ARM64 .
Hope that helps. I also pulled the insiders VSCode for ARM64. Loads in a second.
> node -p «process.arch» arm64
Don’t forget you need xcode-select —install command line tools (
Depending on your project dependencies, you might find it necessary to run node on an x86 architecture as it may get you past frustrating errors on older versions of node. If like me you had already installed node in your attempts here, you can use the following to help get you sorted (assuming you have already installed NVM):
Consider replacing 14 above with whichever node version you are attempting to run under.
After installing, you can run node followed process.arch to confirm that node is running in x64 mode:
From node v16.x:
PS: node v16 has problems with serverless-offline. I managed to solve it using node v15.4.0
From node v15.x:
Nvm install 14.15.3 (current LTS) wasn’t successful for me in any of the attempts (with brew arch -x86_64 prefix as well). But, I was able to:
- install nvm from github (with putting the «export» string to
/.zhrc and executing it)
Open Terminal Using Rosseta 2 if you haven’t installed rosseta2 yet Just Check out my blog to set up it
Install Homebrew using this command.
Now hit this command to install nodejs or anything you want
Источник
Apple Silicon Support #37309
Comments
AshCripps commented Feb 10, 2021 •
This issue to provide visibility about our plans and progress to supporting Apple Silicon natively.
Current plan is to have native support for 16.x via a universal binary supporting both Arm and Intel architecture.
NOTE: Support is very unlikely to be back ported to 14.x or before due to requiring a SemVer Major V8 update
How to run Node.js on Apple Silicon currently
You can either build from source on 15.x — This is not officially supported so don’t expect a smooth experience
You can also run x64 Node.js binaries via the translation layer.
Current Known Bugs
- Check failed: allocator->SetPermissions — #37061 — #37276 has landed.
- make check failure — #36656 — #37471 has landed.
To Do List
- Add 11.0 to versionselector to ensure we build only on master
- Enable the macos-arm job in normal test regressions
- Get the DTKs back into CI for testing
- Test compiling and running node natively on the mac arm hardware
- Test if a current release runs on the new hardware through the translation layer
- Figure out a source of hardware to add to our CI for when our DTKs go back to apple
- Note down size difference in binaries between: intel, arm and fat.
- Change makefile to build universal binaries
- Edit release job to build the new binary
This issue is locked as we will use it to provide updates on progress. If you need help please open an issue on https://github.com/nodejs/help/issues
The text was updated successfully, but these errors were encountered:
AshCripps commented Feb 25, 2021
node-test-commit-osx-arm is now enabled in the regular CI runs (example run: https://ci.nodejs.org/job/node-test-commit/44655/). I will be keeping an eye on it to check thats its working correctly
targos commented Mar 10, 2021 •
Change makefile to build universal binaries
Has someone looked into this? It seems that it can be done independently of the other steps, and since v16.0.0 is quite close, I think it would be nice if we could start building the fat binary for nightlies.
AshCripps commented Mar 10, 2021
I haven’t had the time yet, but its open to anyone interested in helping out.
AshCripps commented Mar 10, 2021
Also today I got 3 M1 minis from macstadium so Im setting them up today
AshCripps commented Mar 18, 2021
I tried cross compiling on a M1 to intel arch using some steps in nodejs/build#2474 (comment) but hit the following error:
@rvagg I am a total novice at this so is there anything obvious that sticks out about this error?
rvagg commented Mar 19, 2021
Yeah, whacky, it’s V8 blocking this:
Lines 151 to 154 in 52f9aaf
# if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT && \ |
!(V8_HOST_ARCH_X64 && V8_HOST_ARCH_64_BIT)) |
# error Target architecture x64 is only supported on x64 host |
# endif |
So V8 has opinions about which direction you can cross-compile. That whole surrounding section has strong assertions about which host->target combinations you can cross-compile V8 in. I don’t really understand why they need to have such opinions but I guess they have some pretty deep architecture affinity things going on where they have constraints for what to practically support. @targos comes to mind as someone who might have some insight into the why here.
But this does answer the question we had at the meeting this week — can we support both architectures on an arm64 release host — NO, for now at least. x64 reigns supreme. So we need to invest in getting the x64->arm64 cross path working cleanly so we can do fat binaries for the .pkg.
Источник
macOS Big Sur: How to setup Node.js on Apple M1 Machine
Recently I bought an Apple’s M1 Macbook Pro. As I am still transitioning from my old MacBook, it might be helpful to document some findings from the developer perspective, especially for developers working with javascript stuff on a daily basis like me.
So far, the transitions are pretty smooth, and many developer tools have also been updating their latest versions to work natively with the M1 machine (yes, including docker).
If you are installing Node.js, I recommend using Node Version Manager (nvm) over Homebrew. It’s similar to RVM (Ruby Version Manager) for Ruby language that allows you to switch between Node versions, which is essential easily.
Install the latest version.
Restart terminal and run the final command.
Confirm that you are using the latest version of Node and npm.
First, confirm that you are on arm64
Sometimes you still need to work on x64 architecture. Most likely because some of the libraries or npm packages that you are using are not working natively with M1 yet.
Switch to x64 architecture environment.
check that the architecture is correct.
Install node using nvm. This should download the precompiled x64 binary:
Now, check that the architecture is correct:
It is now safe to return to the arm64 zsh process:
We’re back to a native shell:
Create a Rosetta Terminal
You can also set the Open using Rosetta option on Terminal.app or iTerm.app until more stuff works with arch64 and the toolchain on the M1 macs (most if not all of this stuff already works, though).
- Right click the app (Terminal, iTerm, etc.)
- Tap «Get Info»
- Select «Open using Rosetta»
- Restart terminal
But I’d prefer the former way, because by using arch -x86_64 zsh you can use Rosetta on a need to use base and not need to run the whole terminal in Rosetta mode.
Finding and installing native applications
Right now, there are still a few applications that don’t offer full native support for Apple Silicon. So we have to install the x86_64 versions of these applications. This means that Rosetta will run in the background to translate the application and make it compatible to run on the M1, but this also means that it will not run fully ARM optimized.
You can visit the website “Does it ARM?” or Is Apple silicon ready? and search for any app. It’s a great resource to find and install Apple Silicon versions of your apps.
That’s it. I hope it helped speed up your process of developing apps on your Apple Silicon Macs.
About the author
Hey, I’m Anas, a software engineer and maker of things. I publish articles about modern JavaScript, design, and programming.
Источник
I just got the one of the newest M1-based MacBooks and I wanted to get it up and running as fast as possible so I went with the Migration Assistant and migrated everything from my old MacBook Pro 2017 running macOS 10. To my surprise it worked without any issues at all (I would expect at least it requires same OS versions).
Although it already felt much faster than my previous machine even running most of the software through Rosetta 2 emulation mode, I was still curious: how much faster it actually is when running things natively.
Since the existing Homebrew installation wouldn’t allow my updating or installing packages anymore because of more restrictive OS permissions, I was faced with «update the x86 homebrew» or “use an experimental cutting-edge ARM build”. I went with the latter and this post summarizes my experience.
Step 0. Remove x86 zsh binary
One of the biggest confusion for me was the fact my shell would not run in arm64 mode. This was caused by the fact I already have been using zsh shell before and it was migrated over. The new macOS Big Sur comes with zsh as a default shell so you don’t need to install it separately anymore.
To solve this issue I had to remove x86 compiled zsh that I installed via Homebrew. This cannot be done with brew remove since Homebrew won’t have enough permissions but you can remove zsh manually:
Verify by opening a new terminal session and running arch .
Step 1. Install Apple Silicon version of the Homebrew
To install the ARM version of Homebrew on the Apple Silicon Mac, I used the manual «untar anywhere» method: https://docs.brew.sh/Installation#untar-anywhere
This method allows installing Homebrew alongside with the x86 version which is probably a good idea for a time being since not all packages are yet pre-built for ARM. I had a few issues while building from sources, too.
After installing Homebrew into separate directory, add the following to your .zshrc file
After that you can use both arm64 and x86 installations of Homebrew side-by-side.
Step 2. Install node and yarn
After you have installed Homebrew, install node (which includes npm) normally running brew install node Install Yarn using brew install yarn .
To verify that you’re running the Node in ARM architecture, enable the row «Architecture» in Activity Monitor,
Step 3. Install packages to run Gatsby
After running Node natively I had issues running Gatsby project. While doing npm install in the Gatsby project, it will fail because of the binding for the Sharp — a native C library Gatsby using — needs to be compiled under the ARM architecture. It didn’t work out of the box for me since some native packages were missing. I was able to resolve it following this GitHub issue https://github.com/lovell/sharp/issues/2460 and doing
After that the installation went well and I could run the project. There were no issues whatsoever running other JavaScript projects (using TypeScript or Bable).
So, how much faster is ARM Node compared to x86
I ran a few tests on the same machine and also compared build speeds with my previous MacBook Pro 2017 that has 2,9 GHz i7 Quad Core CPU and 16 GB of RAM.
The results were. astonishing!
Running x86 vs arm64 node resulted in a
40% improvement. Building a Gatsby site with a few dozens of pages went from 55 seconds on MacBook Pro to 15 seconds on MacBook Air!
Источник