It is indispensable for the development of React, Vue, Angular, etc. these days.
The target is macOS, but if you feel like it, you may write the Windows edition.
However, if you have a project you are involved in developing and a setup procedure exists, follow it. This article is for people who don’t have that kind of straitjacket.
This is an article for beginners. If this procedure doesn’t work, or if you have any questions, feel free to comment.
Overview of what to install
First, let’s assume Homebrew , which is a package manager that is indispensable when building a development environment on macOS .
Furthermore, as a countermeasure against version problems, install Node.js after installing the standard version control tool called anyenv + nodenv.
Why not install Node.js directly? Many people may have the question. For example, you could install Node.js with Homebrew, but why not?
You can easily fix the version for each project by using version control tools such as anyenv + nodenv.
See the official for how to install Homebrew .
Already installed person is Homebrew, regularly
brew upgradeplease go to. Homebrew is a mechanism to fetch recipes with git and update them, so when you like “hit the brew command after a long time”, it usually
This is especially annoying when the line is thin.
“What? Install anyenv with homebrew?
brew install anyenv…”
Updating Homebrew...response while in the terminal "
“Pake dies ———-”
When I encounter this kind of phenomenon, I generally lose my motivation, and on that day I tend to read manga.
Homebrew tends to be unstable at some times. Mostly, it is swayed by the version upgrade of macOS and Xcode. Therefore, pay close attention to updating macOS and Xcode. Every year, around autumn, someone screams.
Those who want to develop iOS, macOS, etc. need to have Xcode full size installed. If you don’t, you can just install Command line tools for Xcode.
How to install this Command line tools for Xtools can vary greatly from time to time, so please do something about it.
xcode-select --installYou may or may not be able to install it with. Please survive in a good way!
By the way, even though it is installed, it often works in the fall.
In that case, the solution is often written by reading the document under https://github.com/nodejs/node-gyp . By the way, node-gyp is a system for building native modules of Node.js, and it tends to suffer from almost the same problems as Homebrew, so if you read the documentation of node-gyp, it may solve the problem of Homebrew as well. ..
Most people are suffering, so you can find some information by searching. Good luck! !! !! !! !! !! !! !! !!
I can’t write an article like “I can definitely install this! Preserved version” because almost everyone is swayed by Apple.
Install anyenv with Homebrew
anyenv is a
rbenvtool for managing version control tools that supports version control tools for various languages, including those for Ruby .
- Install anyenv
- Use anyenv to install * env for each language
The general flow is.
So, use Homebrew to install anyenv .
$ brew install anyenv $ anyenv init
If you get a message, follow the message. Maybe
eval "$(anyenv init -)"I’d be told white add something like one.
anyenvIf you have installed and successfully initialized, you will see
anyenv install -la list of things you can install with.
$ anyenv install -l Renv crenv denv erlenv exenv goenv hsenv jenv luaenv nodenv phpenv plenv pyenv rbenv sbtenv scalaenv swiftenv tfenv
Install nodenv with anyenv
There are several types of version control tools, some of which have been abandoned for maintenance. There are many maintenance abandonments despite the fact that this kind of tool is crowded.
As of November 2020, anyenv only supports nodenv, so please include nodenv.
However, if your project employs other version control tools, somehow install it. Rather, do not follow the steps in this article, but follow the steps specified in your project. This article is for those who do not have such a designation.
This kind of article often introduces other “tools that are no longer maintained”. This article may be like that, but in that case, if you write in the comment “Nodenv is no longer maintained, use xxxxxx”, I think that later people will be saved.
$ anyenv install nodenv
If the installation is successful, finally,
Install nodenv succeeded! Please reload your profile (exec $SHELL -l) or open a new session.
I think that is displayed.
anyenvIn the system, version control is performed by crafting the shell while it is running, so you
exec $SHELL -lcan not update unless you hit and log in to the shell.
exec $SHELL -l
exec $SHELL -lhave trouble with anyenv or nodenv, please.
Install Node.js with nodenv
You need to know the version number because you want to specify the version number you want to install.
As a general rule, odd versions are so-called development versions. Beginners should not touch 11 or 13 or 15. I usually cry.
Is it a stable version if it is an even version? That may not be the case due to the Node.js release cycle.
Looking here, it says “14.15.0 LTS recommended version”. If you think that even numbers up to the major version specified as the recommended version are stable versions, it is almost correct.
You might think, “Well, then 12 or 10 or 8 is a stable version?", But a version that is too old is an “unmaintained version.”
See the table at the bottom of the release schedule for more details, but 8.x is no longer maintained and 10.x will die on April 30, 2021.
- If the project has a fixed version, please install the “specified version”
- If not, please install the version recommended on the official top page.
- If you like things that don’t cry when you fall, you may install the latest version, but those weird people don’t need to read this article for beginners.
Here, it is assumed that the recommended version as of November 8, 2020, where the article is written, is
$ nodenv install 14.15.0
It is not necessary to add it
14.15.0before this time
If you get an error, please go through the message that appears.
nodenv: default-packages file not found If you come up with something like that, you can read the Qiita-like article that came out and you will find a solution.
$ touch $(nodenv root)/default-packages
Generally, this kind of tool will give errors depending on the time, so please do something about it. If you are unlucky, you will get an error, so do your best! !! !! !! !!
Select version with nodenv
Version control tools of this type have concepts like “whole” and “project”. If the version is not fixed for each project, the version set in “Whole” will be used. It means that the version of Node.js depends on the current directory you are working in.
10.18.0let’s say it is fixed at.
10.15.3assume that it is fixed with.
node -vare below the directory, it
v10.15.3return if it is below the directory
- Otherwise, it will return the globally installed version
nodenv versions Will display a list of Node.js versions installed by nodenv and the currently selected version.
$ nodenv versions system 10.15.3 10.16.0 10.18.0 12.6.0 * 12.16.0 (set by /Users/...........) 14.15.0
In this case,
12.16.0is the globally specified version.
To specify globally
nodenv global xxxxxx, specify as follows.
$ nodenv global 14.15.0 $ node -v v14.15.0 $ nodenv versions system 10.15.3 10.16.0 10.18.0 12.6.0 12.16.0 * 14.15.0 (set by /Users/..............)
If it doesn’t succeed, the anyenv installation has failed, you have installed nodenv but you
exec $SHELL -lhaven’t run it, your login shell startup script contains extras, you don’t have what you need, etc. is.
Good luck! !! !!
If you want to fix the version locally
nodenv local xxxxx.
$ nodenv local 12.16.0 $ node -v v12.16.0 $ ls -al total 2392 ... -rw-r--r-- 1 erukiti 8 11 8 19:19 .node-version ... $ cat .node-version 12.16.0
nodenv local xxxx.node-versionA file called is generated in the directory where the version name is written. If you want to fix the version, you
.node-versionshould also commit to the project repository.
yarncase to be installation errors and the, the version of engagement is bad https://github.com/nodejs/node-gyp you may be able to solve If you read.
If the version does not fit well, that’s what it is, so look for a version that fits well. Since it is likely to be a prey to destructive changes, there are cases where it is necessary to modify the source code without solving it by just specifying the version. At that time, please listen to the person who is moving. If no one is moving, do something while crying. Good luck! !! !!
The latter is mostly bad for macOS and Xcode, so try to dig around while resenting Apple. I think someone is crying and posting a solution.
Those who install Xcode beta or macOS beta are at their own risk! I usually cry.
- Homebrew is a must, but macOS and Xcode versions tend to be demons. Especially autumn
- Depending on the time and version combination, if you are unlucky, you tend to run into trouble. The fate of macOS. Good luck! !! !!
- If you have any problems, read the node-gyp documentation from the beginning, or do your best! !! !!
First If you encounter trouble
nodenv versionsand to make sure it would be nice.
Mostly macOS and Xcode are bad.