npm install failing after nvm based LTS install in Dockerfile - node.js

I am trying to create a centos image with latest node.js LTS version and a npm package. Everything works until the npm command which then fails with the following error:
> [5/5] RUN npm install -g express-generator-typescript:
#8 1.928 /bin/sh: npm: command not found
Here is my Dockerfile:
FROM centos
RUN touch $HOME/.bashrc && \
yum -y install tar gzip gunzip
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash \
&& . $HOME/.bashrc \
&& nvm install --lts
RUN npm install -g express-generator-typescript
Note:
I want nvm to dynamically install the latest LTS version of node.js.
If I typed the same commands in a centos container, I can install the NPM package.
How do I solve this problem?

Related

How to set up Truffle and Ganache with Docker on Apple Silicon

error - node-gyp-build: Permission denied while setting up truffle and ganache with docker on Apple Silicon
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v17.9.0/lib/node_modules/truffle/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: 1: node-gyp-build: Permission denied
These are some steps i followed to install truffle with docker on my m1 Macbook.
I'll be doing it for ubuntu image container
docker run -it ubuntu
on your container execute below:
apt-get update && apt-get upgrade
apt-get install sudo build-essential python3 wget curl
Then install nvm from https://github.com/nvm-sh/nvm#install--update-script
On above link there must be these two commands but with updated versions
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
then install node and npm with:
nvm install node
node install npm
npm install npm
after executing
nvm install-latest-npm
you'll find a statement to update npm to the latest version, execute that command, which should look like, npm install -g npm#8.6.0, after that install truffle
npm install -g truffle
there will be a permission issue in executing above command for which you've to execute
sudo chown -R $(whoami) <path to node_modules directory>
Note: the above command has path to node_modules you need to find the path to your node_modules from your error. in my case it was /root/.nvm/versions/node/v17.9.0/lib/node_modules/ so i executed, sudo chown -R $(whoami) /root/.nvm/versions/node/v17.9.0/lib/node_modules/
retry npm install -g truffle
after this you should be done with installation, but you would face problems where you couldn't execute the truffle file.
for this just allow your truffle file to be executed by running:
chmod u+x <path to truffle> you may find the path to truffle with which truffle, execute as below.
chmod u+x /root/.nvm/versions/node/v17.9.0/bin/truffle
For Ganache installation:
npm install ganache --global
To your package.json add,
"scripts": {
"ganache": "ganache --wallet.seed myCustomSeed"
}
Then execute,
npm run ganache
you should be able to see output something like RPC Listening on 127.0.0.1:8545
now execute truffle console, make sure you add correct port number like above 8545 in file truffle-config.js of your code, when you use it.
now execute truffle console

Permission denied while trying to install opencv4nodejs in Ubuntu

I was trying to install opencv4nodejs in Ubuntu-20.04 using the following command and my node version is v12.19.0
sudo npm i -g opencv4nodejs
But getting those errors
info install installing opencv version 3.4.6 into directory: /usr/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv
ERR! Error: Command failed: mkdir -p opencv
mkdir: cannot create directory ‘opencv’: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv-build#0.1.9 install: `node ./install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the opencv-build#0.1.9 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-10-28T06_33_21_090Z-debug.log
Running NPM install with sudo might be causing a permissions problem. You could try completely removing the node_modules directory and re-running NPM install it without sudo.
Also make sure you have permission to write to the directory you're installing in?
If it still doesn't work please follow this:
sudo npm install -g opencv4nodejs --unsafe-perm=true --allow-root
This is complete guide to install opencv4nodejs to Linux OS or Raspberry pi (Raspberry Pi OS )
configuration
01- sudo raspi-config expand file system // this is for raspberry pi
After Reboot (sudo reboot now)
02- df -h (To check expand file system)
03- sudo apt-get update && sudo apt-get upgrade -y
04- sudo passwd root // set up your root password
Reboot
To Install NodeJS
01- sudo apt-get install git -y
02- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - // replase 12 with latest nodejs (LTS) version
03- sudo apt-get install nodejs -y
04- sudo apt-get install gcc g++ make
To Install opencv4nodejs
01. sudo apt-get install cmake -y
02. sudo npm install -g node-gyp
I am using this steps for raspberry pi os
03. sudo nano /etc/dphys-swapfile
(Increase the CONF_SWAPSIZE from 100 to 1024)
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
cd to home dir..
04. mkdir opencv
05. cd opencv
06. sudo npm init -y
07. su
// Enter your setup root password
08. sudo npm install --save opencv4nodejs
09. sudo nano /etc/dphys-swapfile
(Set the CONF_SWAPSIZE back to 100)
In index.js and node_modules in same folder
const cv = require("opencv4nodejs");
In index.js and node_modules in not in same folder
const cv = require("path/opencv/node_modules/opencv4nodejs");
! you don't need to install opencv4nodejs for each folders
You can simply call that above way
Hope guys you can understand it...
Any questions feel free to ask...
Thank you

compser -v doesn't show version and composer-playground command not not found on ubuntu 16.04

I ran all the installations
npm install -g composer-cli ,
npm install -g composer-rest-server
npm install -g generator-hypeldger-composer
npm install -g yo
npm install -g composer-playground
.
These commands have executed without any errors and I was able to view them at ~/.npm-global/lib/node_modules$ but I run composer --version it is not showing the version Composer version #package_branch_alias_version# (1.0.0-beta2) 2016-03-27 16:00:34, and composer-playground: command not found.
Please do suggest if I need to setup any path manually or there is something to fix.
I would run the curl command to install composer on Ubuntu
curl -sS https://getcomposer.org/installer -o composer-setup.php

sudo npm install command not found

I have installed nodejs and npm in my server (os:amazon ami) using node version manager
current node version is 7.10.0
npm version is 4.2.0
nodejs project is located in var/www/testing folder when i am trying to install the depeondeies present in package.json using sudo npm install i got command not found error
Path of node and npm is respectively
~/.nvm/versions/node/v7.10.0/bin/node
~/.nvm/versions/node/v7.10.0/bin/npm
npm and node are in same folder but when I try this command:
sudo npm install I got sudo: npm: command not found
npm install command throws no errors but node_modules folder is empty.
Correct npm path is /usr/local/bin/npm else just run below command again
sudo apt-get install npm
And verify the npm is install, Alternatively you can try:
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
I got this error when I tried to install npm.
bash-3.2$ sudo npm install
sudo: npm: command not found
So, I downloaded node.js from https://nodejs.org/en/
It will automatically set at the required path.
After installation, it worked for me.
Try To Install Node Using Nvm Node Version Manager
From Officai NVM Git Hub Repo
https://github.com/nvm-sh/nvm
git clone https://github.com/nvm-sh/nvm
cd nvm
./installer.sh
nvm install <AnyNodeVersion>
Now Hit Command Line
This Method Actually Worked For ME
i Face same Issue And Explained It Here
https://stackoverflow.com/questions/67285266/npmcommand-not-found-node-v-is-working-but-for-npm-command-not-found

What is the difference between "npm update -g", "npm upgrade -g", "npm install -g npm", and "n stable"?

My npm seems out of date, so it seems I could use four different ways to update it:
sudo npm update -g # => npm 3.8.6
sudo npm upgrade -g # => npm 3.8.7
sudo npm install -g npm
sudo npm cache clean -f && sudo npm install -g n && sudo n stable
Some of the methods above installed npm 3.8.6, some installed 3.8.7, and the last one by n installed 3.8.3.
What are the differences between these methods and is there a standard way / official way to do it?
(The 3.8.6 and 3.8.7 difference was on my MacBook 12 inch Retina with Mac OS X v10.11 (El Capitan). It wasn't so on my MacBook Pro with Mac OS X v10.9 (Mavericks).)
What those commands do:
sudo npm update -g - this command updates all installed global packages to the the latest versions.
sudo npm upgrade -g - it's an alias for update command.
sudo npm install -g npm - installs the latest available version of npm package.
sudo npm cache clean -f && sudo npm install -g n && sudo n stable - cleans the npm cache, installs n (node version manager) and the latest available node.js and npm.
So, if you need update npm to the latest version only, use sudo npm install -g npm, if you want to update and node and npm, use sudo npm cache clean -f && sudo npm install -g n && sudo n stable.

Resources