Add environment variables for Mac

Source: Internet
Author: User
Tags install node

Two problems:

1. nodejs Installation

Use Mac OS X binaries (.tar.gz) (64-bit) for installation:

Http://www.nodejs.org/download/

Installation Reference: http://blog.snowinmay.net /? P = 41

Installation tips:

1.1 clear all the previous nodejs files:

Rm-r bin/node-WAF include/node lib/pkgconfig/nodejs. PC share/man/Man1/node.1

1.2 decompress the file to your favorite directory (preferably the system's default program installation directory, so you do not need to write environment variables)

Environment Variable I wrote: Export Path = "~ /Work/node/bin: $ path"

I encountered a problem when installing nodejs this time because when copying files, I copied the files in the bin folder to another layer:

It should have been like this:

 

Prince-2: node snowinmay $ ls
Changelogreadme. mdincludeshare licensebinlib

Prince-2: node snowinmay $ CD bin/
Prince-2: Bin snowinmay $ ls
Nodenpm

Node and NPM are in Bin. When I copy the node and NPM, they are placed under bin/, so they cannot match the environment variable.

 

2. NPM Installation

NPM errors are divided into two times, the first time is because: curl https://npmjs.org/install.sh | sh write error, prompt error always is:

directory sh: line 2: syntax error near unexpected token<'
'H: Line 2: 'Prince-2: node snowinmay $ sudo NPM install-G npmlog

The correct statement should be:

Curl-0-l http://npmjs.org/install.sh | sudo sh

Prompt after running:

NPM cannot be installed without nodejs.
Install node first, and then try again.

Maybe node is installed, but not in the path?
Note that running as sudo can change envs.

Path = ~ /Work/node/bin:/users/snowinmay /. rvm/gems/ruby-2.0.0-p451/bin:/users/snowinmay /. rvm/gems/[email protected]/bin:/users/snowinmay /. rvm/rubian/ruby-2.0.0-p451/bin:/usr/sbin:/usr/local/bin:/users/snowinmay /. rvm/bin

The system prompts that the environment variable has been written incorrectly. No wonder it was used before: Both which node and which NPM are invalid. Check the environment variable file:

Export Path = "~ /Work/node/bin: $ path "changed:

Export Path = "$ home/work/node/bin: $ path"

Prince-2: Bin snowinmay $ which Node
/Users/snowinmay/work/node/bin/node
Prince-2: Bin snowinmay $ which NPM
/Users/snowinmay/work/node/bin/NPM

Prince-2: Bin snowinmay $ path
-Bash:/users/snowinmay/work/node/bin :~ /Work/node/bin:/users/snowinmay /. rvm/gems/ruby-2.0.0-p451/bin:/users/snowinmay /. rvm/gems/[email protected]/bin:/users/snowinmay /. rvm/rubian/ruby-2.0.0-p451/bin:/usr/sbin:/usr/local/bin:/users/snowinmay /. rvm/bin:/users/snowinmay /. rvm/bin:/users/snowinmay /. rvm/bin: no such file or directory

Run:

Prince-2 :~ Snowinmay $ curl-0-l http://npmjs.org/install.sh | sh
% Total % received % xferd average speed time Time Current
Dload upload total spent left speed
0 193 0 0 0 0 0 --: -- 0
100 6711 100 6711 0 0 2324 0 0:00:02 --: -- 5386
Tar =/usr/bin/tar
Version:
Bsdtar 2.8.3-libarchive 2.8.3
Install [email protected]
Fetching: http://registry.npmjs.org/npm/-/npm-1.4.21.tgz
0.10.29
1.4.21
Cleanup prefix =/users/snowinmay/work/node
Find:/users/snowinmay/work/node/share/MAN: no such file or directory
Find:/users/snowinmay/work/node/share/MAN: no such file or directory
Find:/users/snowinmay/work/node/lib/node: no such file or directory
Find:/users/snowinmay/work/node/lib/node: no such file or directory

All clean!

> [Email protected] prepublish.
> Node bin/npm-cli.js prune -- prefix =. -- no-Global & Rm-RF Test/*/node_modules & make-J8 Doc

Make: Nothing to be done for 'Doc '.
/Users/snowinmay/work/node/bin/NPM->/users/snowinmay/work/node/lib/node_modules/NPM/bin/npm-cli.js
[Email protected]/users/snowinmay/work/node/lib/node_modules/NPM
It worked

Problem ended

==========================================

/Etc/profile;/etc/bashrc is a global variable for all users in the system. Only the root user can modify these two files. Generally, they are read-only. Generally, if you want to modify them, you can add sudo to the command, which means to execute them as root, for example, sudo VI/etc/profile, and then enter the password as prompted.

Therefore, for general users, it is recommended to modify ~ /. Bash_profile is used to set environment variables. It is user-level setting and only valid for the current user. Operation steps: 1. Open terminal (terminal) 2. Enter VI ~ /. Bash_profile 3. Set path: Export Path =/usr/local/MySQL/bin: $ Path 4. Enter: WQ // save and exit VI. 5. The modification takes effect immediately: Source ~ /. Bash_profile 6. view the environment variable value: Echo $ PATH Note: 1 ,~ /. Bash_profile has a point 2. If you are adding an environment variable or modifying the value of the environment variable, you need to set source to take effect immediately. To delete an environment variable, you must enter exit to start the current logout shell, and then re-open a new shell and login to take effect.

Prince-2 :~ Snowinmay $ Vim. bash_profile

Prince-2 :~ Snowinmay $ source ~ /. Bash_profile
Prince-2 :~ Snowinmay $ path
-Bash :~ /Work/node/bin:/users/snowinmay /. rvm/gems/ruby-2.0.0-p451/bin:/users/snowinmay /. rvm/gems/[email protected]/bin:/users/snowinmay /. rvm/rubian/ruby-2.0.0-p451/bin:/usr/sbin:/usr/local/bin:/users/snowinmay /. rvm/bin:/users/snowinmay /. rvm/bin: no such file or directory

However, NPM is still unavailable:

Prince-2: node snowinmay $ node-V
V0.10.29
Prince-2: node snowinmay $ NPM-V

Module. JS: 340
Throw err;
^
Error: cannot find module 'npmlog'
At function. Module. _ resolvefilename (module. JS: 338: 15)
At function. Module. _ load (module. JS: 280: 25)
At module. Require (module. JS: 364: 17)
At require (module. JS: 380: 17)
At/users/snowinmay/work/node/bin/NPM: 19: 11
At object. <anonymous> (/users/snowinmay/work/node/bin/NPM: 87: 3)
At module. _ compile (module. JS: 456: 26)
At object. Module. _ extensions.. js (module. JS: 474: 10)
At module. Load (module. JS: 356: 32)
At function. Module. _ load (module. JS: 312: 12)
Prince-2: node snowinmay $
Prince-2: node snowinmay $
Prince-2: node snowinmay $ make install
Make:*No rule to make targetinstall‘. Stop. Prince-2:node snowinmay$ curl https://npmjs.org/install.sh | sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 193 100 193 0 0 119 0 0:00:01 0:00:01 --:--:-- 153 sh: line 1: html: No such file or directory sh: line 2: syntax error near unexpected token<'
'H: Line 2: 'Prince-2: node snowinmay $ sudo NPM install-G npmlog
Password:
Sudo: NPM: Command not found
Prince-2: node snowinmay $
Prince-2: node snowinmay $ which Node
Prince-2: node snowinmay $ which NPM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.