Trouble installing topojson on ubuntu

2019-04-27 23:35发布

问题:

I've been trying to install topojson by following Mike Bostock's Let's Make a Map tutorial http://bost.ocks.org/mike/map/ and I believe I have managed to get the most recent version of Node.js and npm. $which ogr2ogr works as well. I'm quite new to programming and Ubuntu and would sincerely appreciate some thorough help as to why npm install topojson -g yields the following errors. When I try the same command with sudo it yields errors like: npm ERR! registry error parsing json and gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead

Thanks!

npm ERR! Error: EACCES, open '/home/natecraft/.npm/7edf76d6-topojson.lock'
npm ERR!  { [Error: EACCES, open '/home/natecraft/.npm/7edf76d6-topojson.lock']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/home/natecraft/.npm/7edf76d6-topojson.lock' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Linux 3.5.0-23-generic
npm ERR! command "/home/natecraft/.nvm/v0.10.15/bin/node" "/home/natecraft/.nvm/v0.10.15/bin/npm" "install" "topojson" "-g"
npm ERR! cwd /home/natecraft/Downloads/node-latest-install
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.5
npm ERR! path /home/natecraft/.npm/7edf76d6-topojson.lock
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/home/natecraft/.npm/7edf76d6-topojson.lock'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/natecraft/Downloads/node-latest-install/npm-debug.log
npm ERR! not ok code 0

回答1:

First, please check your version of node.js -- use the stable version, not the devel version. Second, invoke the npm command as superuser.

$ sudo npm install -g topojson

So far, when I switch my node.js into stable version, TopoJSON installation is running well. Thank you for your attention.



回答2:

I came across this error when installing topojson (Debian 3.2.0-4-amd64). My steps to get things working (also discussed here).

Install node v 0.11.10

git clone https://github.com/joyent/node.git
cd node
git checkout v0.11.10
./configure && make
sudo make install

Remove debian gyp and install via npm:

sudo apt-get remove gyp
npm install -g gyp

Explicitly install contextify, although that was the version already installed.

npm install contextify@0.1.7

then, installing topojson should work

sudo npm install -g topojson