| | @@ -2,37 +2,25 @@ |
| |
|
| | A quick guide on how to setup Node.js development environment. |
| |
|
| | Previous versions of these install instructions had been tested with: |
| |
|
| | - [Debian 10 (buster)](https://www.debian.org/News/2019/20190706) |
| | - [Ubuntu on WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/about) |
| | - [Ubuntu 18.04 LTS (Bionic Beaver)](http://releases.ubuntu.com/bionic/) |
| | - [Ubuntu 17.04 (Zesty Zapus)](http://releases.ubuntu.com/xenial/) |
| | - [Ubuntu 16.04 LTS (Xenial Xerus)](http://releases.ubuntu.com/xenial/) |
| | - [Ubuntu 14.04.3 LTS (Trusty)](http://releases.ubuntu.com/trusty/) |
| | - [macOS 10.14.6 (Mojave)](https://apple.wikia.com/wiki/MacOS_10.14.6) |
| | - [macOS 10.13.6 (High Sierra)](https://apple.wikia.com/wiki/MacOS_10.13.6) |
| | - [macOS 10.12.6 (Sierra)](https://apple.wikia.com/wiki/MacOS_10.12.6) |
| | - [OS X 10.11.6 (El Capitan)](https://apple.wikia.com/wiki/OS_X_10.11.6) |
| |
|
| |
|
| | ## Install `nvm` for managing Node.js versions |
| |
|
| | The reason for using [nvm](https://github.com/nvm-sh/nvm) instead of other install types is mainly in how easy it is to have multiple versions of Node.js (if needed) without too much of extra complexity. Sometimes applications might require a certain version of Node.js to work, so having the flexibility of using specific versions can save a lot of time from you. |
| | [nvm](https://github.com/nvm-sh/nvm) allows installing several versions of Node.js to the same system. Sometimes applications require a certain versions of Node.js to work. Having the flexibility of using specific versions can help. |
| |
|
| | 1. Open new _Terminal_ window. |
| | 2. Run [nvm](https://github.com/nvm-sh/nvm) installer |
| | - ...with _either_ `curl` *or* `wget`, depending on what you have on your computer. |
| | - … with _either_ `curl` *or* `wget`, depending on what your computer has available. |
| | - `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash` |
| | - `wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash` |
| | - The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc,` `~/.profile,` or `~/.bashrc`). (You might want/need to add the source loading line by yourself, if the automated install tool does not add it for you.) |
| | - The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc,` `~/.profile,` or `~/.bashrc`). (You can add the source loading line manually, if the automated install tool does not add it for you.) |
| |
|
| | ```sh |
| | export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" |
| | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm |
| | ``` |
| |
|
| | - If you know where the directory should be, that could be adjusted to the following so that `nvm` is only loaded if the directory exists. (Useful if you have a dotfiles repository, and want to have reusable command line configuration between different systems.) |
| | - Another option: when you have consistent directory location between systems, following example Bash/Zsh configuration allows to load `nvm` when the directory exists. |
| | This allows more consistent sharing of your shell configuration between systems, improving reliability of rest of your configuration even when nvm does not exist on a specific system. |
| |
|
| | ```sh |
| | if [ -d "$HOME/.nvm" ]; then |
| | @@ -47,12 +35,12 @@ The reason for using [nvm](https://github.com/nvm-sh/nvm) instead of other insta |
| | fi |
| | ``` |
| |
|
| | 3. If everything went well, you should now be able to reload the shell by running |
| | 3. If everything went well, you should now either open a new Terminal window/tab, or reload the shell configuration by running: |
| | - `source ~/.bashrc` |
| | - (Another option is to open a new Terminal window/tab.) |
| | 4. Verify installation |
| | - To verify that nvm has been installed, do: `command -v nvm` |
| | 5. List what versions of Node are currently installed (probably none). |
| | - To check if nvm command got installed, run: |
| | - `command -v nvm` |
| | 5. List installed Node.js versions with: |
| | - `nvm ls` |
| | 6. Install latest LTS Version of [Node.js](https://nodejs.org/en/). |
| | - `nvm install v12.14.1` |
| | @@ -62,19 +50,20 @@ The reason for using [nvm](https://github.com/nvm-sh/nvm) instead of other insta |
| | - `nvm install v10.18.1` |
| | 9. If you want to change the default Node version later, you can run a command to adjust it. |
| | - `nvm alias default v12.14.1` [changelog](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#12.14.1) |
| | - `nvm alias default v13.7.0` [changelog](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V13.md#13.7.0) (if you are testing compatibility with future Node.js features) |
| | - `nvm alias default v13.7.0` [changelog](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V13.md#13.7.0) (if you use Node.js features from the Current release) |
| | - `nvm alias default v10.18.1` [changelog](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V10.md#10.18.1) (if you need to use old version of Node.js for older projects) |
| |
|
| | It is also possible to select what Node.js version is used per project basis, by running `nvm use v10.16.3` (or another version number) on a directory where your project's files are located. One way to do that is to create small Bash shell script for enabling the right environment variables when needed, so you would not have to remember what exact version was needed. |
| | You can select Node.js version by running `nvm use v13.7.0` (or another version number). Another alternative: create a small Bash shell script to enable the right environment variables for your project. |
| |
|
| | It is also a good idea to have a look at the [Long Term Support (LTS) schedule](https://nodejs.org/en/about/releases/ "Releases | Node.js"). |
| | Read the Node.js [Long Term Support (LTS) schedule](https://nodejs.org/en/about/releases/ "Releases | Node.js") to have more understanding of their release roadmap. |
| |
|
| | You can find a lot of packages from the [npm](https://www.npmjs.com/) package repository. Have a good time with the freshly installed tools. |
| | [npm](https://www.npmjs.com/) package repository has a lot of packages to discover. |
| | Have a good time with the freshly installed tools. |
| |
|
| |
|
| | ## Migrating packages from the previously installed Node.js versions |
| | ## Migrating packages from a previous Node.js versions |
| |
|
| | If you already have previous version of Node.js installed with nvm, you can migrate packages from previously installed Node.js versions. |
| | If you already have existing Node.js version via `nvm`, you can migrate older packages from the installed Node.js versions. |
| |
|
| | - Open new Terminal window (to make sure you have latest Node.js version active in your command line environment). |
| | - Before running next commands, remember to switch to the right version of Node with `nvm use` command. |
| | @@ -89,34 +78,36 @@ If you already have previous version of Node.js installed with nvm, you can migr |
| |
|
| | ### Deleting old Node.js versions |
| |
|
| | - Look what versions are installed: |
| | - Check installed Node.js versions with: |
| | - `nvm ls` |
| | - Delete an older version (if it is no longer used in some of your projects): |
| | - Delete an older version (if you don't use it in some of your projects): |
| | - `nvm uninstall v12.14.0` |
| | - `nvm uninstall v13.5.0` |
| | - `nvm uninstall v10.18.0` |
| | |
| | ### Updating outdated packages |
| | |
| | #### List what (top level) packages are installed globally |
| | #### List of globally installed top level packages |
| | |
| | ```sh |
| | npm ls -g --depth=0. |
| | ``` |
| | |
| | #### List what packages are outdated |
| | #### List outdated global packages |
| | |
| | ```sh |
| | npm outdated -g --depth=0. |
| | ``` |
| | |
| | #### Update outdated globally installed npm packages |
| | #### Updating all globally installed npm packages |
| | |
| | ```sh |
| | npm update -g |
| | ``` |
| | |
| | #### Command line aliases for Bash & zsh |
| | #### CLI aliases for Bash & Zsh environments |
| | |
| | Example configuration for your Bash & Zsh command line environments. |
| | |
| | ```sh |
| | |
| | @@ -135,15 +126,33 @@ alias update-npm-packages="npm update -g" |
| | |
| | ``` |
| | |
| | |
| | #### Fixing old package versions |
| | |
| | After installation of Node v10.x (or similar), it can be a good idea to recompile old packages (that have compiled native extensions) to make sure that they work with the new version of Node. That can be done easily by going to a project’s root directory, and running `npm rebuild`: |
| | If you have older npm packages with compiled native extensions, recompiling native extensions can improve compatibility with the new Node.js version. Go to your project’s root directory, and run `npm rebuild` command. |
| | |
| | ```sh |
| | cd PROJECT_NAME |
| | npm rebuild |
| | ``` |
| | |
| | |
| | ## Notes about this documentation |
| | |
| | [@d2s](https://github.com/d2s "GitHub profile of Daniel Schildt") tested older versions of these install instructions with: |
| | |
| | - [Debian 10](https://www.debian.org/News/2019/20190706) |
| | - [Ubuntu on WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/about) |
| | - [Ubuntu 18.04 LTS](http://releases.ubuntu.com/bionic/) |
| | - [Ubuntu 17.04](http://releases.ubuntu.com/xenial/) |
| | - [Ubuntu 16.04 LTS](http://releases.ubuntu.com/xenial/) |
| | - [Ubuntu 14.04.3 LTS](http://releases.ubuntu.com/trusty/) |
| | - [macOS 10.14.6 (Mojave)](https://apple.wikia.com/wiki/MacOS_10.14.6) |
| | - [macOS 10.13.6 (High Sierra)](https://apple.wikia.com/wiki/MacOS_10.13.6) |
| | - [macOS 10.12.6 (Sierra)](https://apple.wikia.com/wiki/MacOS_10.12.6) |
| | - [OS X 10.11.6 (El Capitan)](https://apple.wikia.com/wiki/OS_X_10.11.6) |
| | |
| | |
| | ## Contributions |
| | |
| | If you notice some details that could be simpler & better, add a comment under the [original Gist by @d2s](https://gist.github.com/d2s/372b5943bce17b964a79 "Installing Node.js to Linux & macOS & WSL with nvm") with your documentation improvement suggestions. If you were reading an older (forked) version of this document, consider checking the original Gist in case there are more recent updates. |
| | If you have improvement suggestions to make these instructions simpler & better, post a comment under the [original Gist by @d2s](https://gist.github.com/d2s/372b5943bce17b964a79 "Installing Node.js to Linux & macOS & WSL with nvm") with your documentation improvement suggestions. If reading a forked version of the document, check the original Gist for a more recent instructions. |