I am trying to install Node in eg. version 12.18.2 for user dev.
There is no issue when I'm doing it via command line.
Theoretically, I run the same commands from Ansible on a server and there is still the first version installed. I wonder how to make Ansible change version already installed on a server.
This is how I install nvm:
- name: Install nvm
ansible.builtin.shell: >
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh | bash
args:
executable: /bin/bash
chdir: "$HOME"
creates: "$HOME/.nvm/nvm.sh"
- name: Setup .profile
ansible.builtin.lineinfile:
path: ~/.profile
line: source ~/.nvm/nvm.sh
create: yes
- name: Install node
ansible.builtin.shell: |
source ~/.profile & nvm install {{ item }}
args:
executable: /bin/bash
chdir: "$HOME"
creates: "$HOME/.nvm/versions/node/v{{item}}"
loop:
- 12.18.2
When running this code first time, there is issue with /bin/bash: nvm: command not found, when running second time Ansible informs that it's skipping this installation step as it's already installed. I want user dev to use this installed version so I added this task that will use a specific version for a specific user:
- name: Change version
become_user: dev
ansible.builtin.shell: |
source ~/.profile & nvm use {{ item }}
args:
executable: /bin/bash
chdir: "$HOME"
creates: "$HOME/.nvm/versions/node/v{{item}}"
loop:
- 12.18.2
The output is the same as it's with install step:
ok: [my-server] => (item=12.18.2) => changed=false
ansible_loop_var: item
cmd: |-
source ~/.profile & nvm use 12.18.2
item: 12.18.2
rc: 0
stdout: skipped, since /home/dev/.nvm/versions/node/v12.18.2 exists
stdout_lines: <omitted>
When running the same command directly on a a server I get proper output:
dev#my-server:$ nvm use 12.18.2
Now using node v12.18.2 (npm v6.14.5)
Also the strange this is, when running install nvm step for other version like 12.18.1, I'm getting this:
TASK [nodejs : Install node] ***********************************************************************************************************************************************************************
task path: /server/nodejs/tasks/main.yml:120
Monday 05 December 2022 09:01:41 +0100 (0:00:00.870) 0:00:09.360 *******
failed: [my-server] (item=12.18.1) => changed=true
ansible_loop_var: item
cmd: |-
source ~/.profile & nvm install 12.18.1
delta: '0:00:00.452931'
end: '2022-12-05 09:01:43.287552'
item: 12.18.1
msg: non-zero return code
rc: 127
start: '2022-12-05 09:01:42.834621'
stderr: '/bin/bash: nvm: command not found'
stderr_lines: <omitted>
stdout: ''
stdout_lines: <omitted>
But I am sourcing .profile before installation source ~/.profile & nvm install {{ item }}
Of course when I use command line on a server there is no issue even without sourcing the .profile:
dev#my-server:$ nvm install 12.18.1
Downloading and installing node v12.18.1...
Downloading https://nodejs.org/dist/v12.18.1/node-v12.18.1-linux-x64.tar.xz...
############################################################################################################################################################################################# 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.18.1 (npm v6.14.5)
dev#my-server:$ node --version
v12.18.1
dev#my-server:$ nvm install 12.18.0
Downloading and installing node v12.18.0...
Downloading https://nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz...
############################################################################################################################################################################################# 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.18.0 (npm v6.14.4)
TLTR
When using nvm use Ansible skip step and inform it's already installed (Yes, it's installed, but I want to use it, not install it using nvm use).
When using nvm install for not installed version Ansible informs that /bin/bash: nvm: command not found even when sourcing ~/.profile before installation.
Doing the same via command line works perfectly. Can somebody help me to find what am I doing wrong via Ansible?
EDIT: Thanks #β.εηοιτ.βε for pointing that creates in Change version step that should be remove. Now looks like Ansible changed version, but not exactly:
TASK [nodejs : Change version] *********************************************************************
changed: [my-server] => (item=12.18.4) => changed=true
ansible_loop_var: item
cmd: |-
source ~/.profile && nvm use 12.18.4
delta: '0:00:01.658122'
end: '2022-12-05 09:40:57.817836'
item: 12.18.4
rc: 0
start: '2022-12-05 09:40:56.159714'
stderr: ''
stderr_lines: <omitted>
stdout: Now using node v12.18.4 (npm v6.14.6)
stdout_lines: <omitted>
TASK [nodejs : WHO] *********************************************************************
changed: [my-server] => changed=true
cmd: whoami
delta: '0:00:00.014623'
end: '2022-12-05 09:46:05.535453'
rc: 0
start: '2022-12-05 09:46:05.520830'
stderr: ''
stderr_lines: <omitted>
stdout: dev
stdout_lines: <omitted>
TASK [nodejs : debug] *********************************************************************
ok: [my-server] =>
msg: dev
TASK [nodejs : Check version] *********************************************************************
changed: [my-server] => changed=true
cmd: node --version
delta: '0:00:00.023858'
end: '2022-12-05 09:46:06.998710'
rc: 0
start: '2022-12-05 09:46:06.974852'
stderr: ''
stderr_lines: <omitted>
stdout: v12.18.2
stdout_lines: <omitted>
TASK [nodejs : debug] *********************************************************************
ok: [my-server] =>
msg: v12.18.2
The issue is that there is still the old version on a dev user when I'm checking. I'm pretty confused why Ansible thinks that version was changed for user dev and then when Ansible checks version for this user it's still the old one.
Related
I have a GitHub Workflow which I also want to run on GitLab CI:
name: Node.js CI
on:
push:
branches:
- '*'
pull_request:
branches:
- master
jobs:
lint:
runs-on: ubuntu-18.04
name: Lint
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: '12'
- run: yarn
- run: yarn lint
build:
runs-on: ubuntu-18.04
name: Build + Test
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: '12'
- run: yarn
- run: yarn build
- run: yarn test
I tried to setup a new job using the Docker executor template:
docker-build:
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile
I modified it to install node:12 and docker-compose but it doesn't work and it feels wrong doing this. Is there an easier/correct way of running Node.js, Docker and docker-compose in the GitLab CI job?
That's what I tried but as said, it fails:
docker-build:
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker --version
- echo "shell" $0
- uname -a
- dnf -y install curl
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | 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
- nvm install 12
- nvm use 12
- curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker-compose --version
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- echo "hello world"
Result:
Pulling docker image docker:latest ...
Using docker image sha256:08bdaf2f88f90320cd3e92a469969efb1f066c6d318631f94e7864828abd7c75 for docker:latest with digest docker#sha256:a61102937d2bda8319882998ef1ffa27387617f6eea6c298b18a05f7fba82c0d ...
Preparing environment 00:01
Running on runner-ed2dce3a-project-27995513-concurrent-0 via runner-ed2dce3a-srm-1625761937-d755bac1...
Getting source from Git repository 00:02
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/.../docker-compose/.git/
Created fresh repository.
Checking out 659d60d0 as test-gitlab-ci...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:00
Using docker image sha256:08bdaf2f88f90320cd3e92a469969efb1f066c6d318631f94e7864828abd7c75 for docker:latest with digest docker#sha256:a61102937d2bda8319882998ef1ffa27387617f6eea6c298b18a05f7fba82c0d ...
$ docker --version
Docker version 20.10.7, build f0df350
$ echo "shell" $0
shell /bin/sh
$ uname -a
Linux runner-ed2dce3a-project-27995513-concurrent-0 4.19.78-coreos #1 SMP Mon Oct 14 22:56:39 -00 2019 x86_64 Linux
$ dnf -y install curl
/bin/sh: eval: line 119: dnf: not found
Update: the answer by Aritra got me a bit further but it's still not working:
Using docker image sha256:08bdaf2f88f90320cd3e92a469969efb1f066c6d318631f94e7864828abd7c75 for docker:latest with digest docker#sha256:a61102937d2bda8319882998ef1ffa27387617f6eea6c298b18a05f7fba82c0d ...
$ docker --version
Docker version 20.10.7, build f0df350
$ echo "shell" $0
shell /bin/sh
$ uname -a
Linux runner-0277ea0f-project-27995513-concurrent-0 4.19.78-coreos #1 SMP Mon Oct 14 22:56:39 -00 2019 x86_64 Linux
$ apk add curl
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
(1/4) Installing brotli-libs (1.0.9-r3)
(2/4) Installing nghttp2-libs (1.42.0-r1)
(3/4) Installing libcurl (7.77.0-r1)
(4/4) Installing curl (7.77.0-r1)
Executing busybox-1.32.1-r6.trigger
OK: 13 MiB in 24 packages
$ apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
(1/53) Upgrading musl (1.2.2-r0 -> 1.2.2-r1)
(2/53) Installing readline (8.1.0-r0)
(3/53) Installing bash (5.1.0-r0)
Executing bash-5.1.0-r0.post-install
(4/53) Installing libgcc (10.2.1_pre1-r3)
(5/53) Installing libstdc++ (10.2.1_pre1-r3)
(6/53) Installing binutils (2.35.2-r1)
(7/53) Installing libacl (2.2.53-r0)
(8/53) Installing libattr (2.4.48-r0)
(9/53) Installing skalibs (2.10.0.0-r0)
(10/53) Installing s6-ipcserver (2.10.0.0-r0)
(11/53) Installing utmps (0.1.0.0-r0)
Executing utmps-0.1.0.0-r0.pre-install
(12/53) Installing coreutils (8.32-r2)
(13/53) Installing findutils (4.8.0-r0)
(14/53) Installing libgomp (10.2.1_pre1-r3)
(15/53) Installing libatomic (10.2.1_pre1-r3)
(16/53) Installing libgphobos (10.2.1_pre1-r3)
(17/53) Installing gmp (6.2.1-r0)
(18/53) Installing isl22 (0.22-r0)
(19/53) Installing mpfr4 (4.1.0-r0)
(20/53) Installing mpc1 (1.2.0-r0)
(21/53) Installing gcc (10.2.1_pre1-r3)
(22/53) Installing musl-dev (1.2.2-r1)
(23/53) Installing libc-dev (0.7.2-r3)
(24/53) Installing g++ (10.2.1_pre1-r3)
(25/53) Installing pcre (8.44-r0)
(26/53) Installing grep (3.6-r0)
(27/53) Installing linux-headers (5.7.8-r0)
(28/53) Installing make (4.3-r0)
(29/53) Installing ncurses (6.2_p20210109-r0)
(30/53) Installing openssl (1.1.1k-r0)
(31/53) Installing libbz2 (1.0.8-r1)
(32/53) Installing expat (2.2.10-r1)
(33/53) Installing libffi (3.3-r2)
(34/53) Installing gdbm (1.19-r0)
(35/53) Installing sqlite-libs (3.34.1-r0)
(36/53) Installing python2 (2.7.18-r1)
(37/53) Installing libblkid (2.36.1-r1)
(38/53) Installing blkid (2.36.1-r1)
(39/53) Installing libcap-ng (0.8.2-r0)
(40/53) Installing setpriv (2.36.1-r1)
(41/53) Installing libmount (2.36.1-r1)
(42/53) Installing libsmartcols (2.36.1-r1)
(43/53) Installing findmnt (2.36.1-r1)
(44/53) Installing mcookie (2.36.1-r1)
(45/53) Installing hexdump (2.36.1-r1)
(46/53) Installing lsblk (2.36.1-r1)
(47/53) Installing libuuid (2.36.1-r1)
(48/53) Installing libfdisk (2.36.1-r1)
(49/53) Installing sfdisk (2.36.1-r1)
(50/53) Installing cfdisk (2.36.1-r1)
(51/53) Installing partx (2.36.1-r1)
(52/53) Installing libeconf (0.3.8-r0)
(53/53) Installing util-linux (2.36.1-r1)
Executing busybox-1.32.1-r6.trigger
OK: 253 MiB in 76 packages
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14926 100 14926 0 0 182k 0 --:--:-- --:--:-- --:--:-- 184k
=> Downloading nvm as script to '/root/.nvm'
=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
OR
=> Append the following lines to the correct file yourself:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
$ export NVM_DIR="$HOME/.nvm"
$ . "$NVM_DIR/nvm.sh"
$ nvm install 12 -s
Downloading and installing node v12.22.3...
Downloading https://nodejs.org/dist/v12.22.3/node-v12.22.3-linux-x64.tar.gz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.22.3 (npm v)
Creating default alias: default -> 12 (-> v12.22.3 *)
$ nvm use 12
Now using node v12.22.3 (npm v)
$ which node
/root/.nvm/versions/node/v12.22.3/bin/node
$ node --version
/bin/sh: eval: line 135: node: not found
dnf is fedora specific. It's RPM package manager.
if you see the Dockerfile of docker:latest you can see that it's using alpine.
FROM alpine:3.13
RUN apk add --no-cache \
ca-certificates \
# DOCKER_HOST=ssh://... -- https://github.com/docker/cli/pull/1014
openssh-client
# set up nsswitch.conf for Go's "netgo" implementation (which Docker explicitly uses)
# - https://github.com/docker/docker-ce/blob/v17.09.0-ce/components/engine/hack/make.sh#L149
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
ENV DOCKER_VERSION 20.10.7
So instead of dnf you would need to do:
apk add curl
I'm looking for a way to install a given version of node via ansible and nvm, the installation of nvm is working as expected because if I connect with the root user, I can execute the command nvm install 8.11.3 but this same command doesn't work with Ansible, I don't understand why.
---
- name: Install nvm
git: repo=https://github.com/creationix/nvm.git dest=~/.nvm version=v0.33.11
tags: nvm
- name: Source nvm in ~/.{{ item }}
lineinfile: >
dest=~/.{{ item }}
line="source ~/.nvm/nvm.sh"
create=yes
tags: nvm
with_items:
- bashrc
- profile
- name: Install node and set version
become: yes
become_user: root
shell: nvm install 8.11.3
...
error log
TASK [node : Install node and set version] *************************************************************************************
fatal: [51.15.128.164]: FAILED! => {"changed": true, "cmd": "nvm install 8.11.3", "delta": "0:00:00.005883", "end": "2018-12-03 15:05:10.394433", "msg": "non-zero return code", "rc": 127, "start": "2018-12-03 15:05:10.388550", "stderr": "/bin/sh: 1: nvm: not found", "stderr_lines": ["/bin/sh: 1: nvm: not found"], "stdout": "", "stdout_lines": []}
to retry, use: --limit .../.../ansible/stater-debian/playbook.retry
It's okay, here's the configuration that works
- name: Install node and set version
become: yes
become_user: root
shell: "source /root/.nvm/nvm.sh && nvm install 8.11.3"
args:
executable: /bin/bash
I think the clue in the output you need is:
"/bin/sh: 1: nvm: not found"
To run a command without including the full path to that command (i.e. nvm rather than /the/dir/nvm/is/installed/in/nvm), then the directory that contains the command, must be in the $PATH environment variable for the shell that runs the command.
In this case it looks like that is not present for the shell that Ansible spawns, versus the shell your interactive commands run in. Change:
- name: Install node and set version
become: yes
become_user: root
shell: nvm install 8.11.3
to
- name: Install node and set version
become: yes
become_user: root
shell: /full/path/to/nvm install 8.11.3
If you don't know what to put in place of '/full/path/to', try either:
which nvm
or
find / -name nvm
I will just post under here, because there are hundreds of these posts.
- name: Install node
become: true
become_user: root
shell: "source /root/.nvm/nvm.sh && nvm install {{ personal_node_version }} && nvm alias default {{ personal_node_version }}"
args:
executable: /bin/bash
worked for me.
This worked for me on Ubuntu 20.04 using nvm version 0.39.1:
- name: Install NVM
shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
args:
creates: "/root/.nvm/nvm.sh"
- name: Install Node Versions
shell: ". /root/.bashrc && nvm install {{item}}"
with_items:
- 'v10.24.1'
- 'v16.17.0'
- '--lts'
- 'node'
Based on all the posts found on stack and tweaked a little for my own needs - I found this solution worked perfectly for both installing NVM (the easy part) and creating a loop that allows you to insert 1 or many versions of Node as needed
# test if nvm has been installed by the user desired
- stat:
path: /home/yournonrootuser/.nvm
register: nvm_path
- name: Setup NodeVersionManager and install node version
become: yes
# Execute config files such as .profile (Ansible uses non-interactive login shells)
become_flags: -i
become_user: yournonrootuser
block:
- name: Install nvm
shell: >
curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
args:
executable: /bin/bash
chdir: "$HOME"
creates: "$HOME/.nvm/nvm.sh"
- name: Setup .profile of yournonrootuser
lineinfile:
path: ~/.profile
# This will make sure Node is on the users PATH
line: source ~/.nvm/nvm.sh
create: yes
become_flags: -i
when: nvm_path.stat.exists == false
# if we got here we already know node version manager is installed
- name: installing node versions using loop
command: sudo -iu yournonrootuser nvm install {{item}}
args:
executable: /bin/bash
chdir: "$HOME"
creates: "$HOME/.nvm/versions/node/v{{item}}"
loop:
- 14.18.3
env: node: No such file or directory
I checked if my directory for node wasn't wrong and it's fine.
I tried these following answers already:
1. https://github.com/nodejs/node-v0.x-archive/issues/3911
2. https://github.com/creationix/nvm/issues/1702
3. browserify error /usr/bin/env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ yarn init
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
acpica fantom lego qmmp
bat fn libdca rubberband
bazel fselect libpqxx ruby-build
cake fstar nativefier saxon
calabash groovysdk openimageio shellcheck
cdrdao h2o pegtl sqlmap
cmake hadoop percona-server teleport
conan heroku phpunit urh
convox jenkins-job-builder pike
etcd jetty ponyc
exomizer jetty-runner pygobject3
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew link node
Linking /usr/local/Cellar/node/10.3.0...
Error: Could not symlink include/node/android-ifaddrs.h
Target /usr/local/include/node/android-ifaddrs.h
already exists. You may want to remove it:
rm '/usr/local/include/node/android-ifaddrs.h'
To force the link and overwrite all conflicting files:
brew link --overwrite node
To list all files that would be deleted:
brew link --overwrite --dry-run node
USER-no-MacBook-Pro-2:nomadcoin user$ brew link --overwrite --dry-run node
Would remove:
/usr/local/include/node/android-ifaddrs.h
/usr/local/include/node/common.gypi
/usr/local/include/node/config.gypi
/usr/local/include/node/libplatform/libplatform-export.h
/usr/local/include/node/libplatform/libplatform.h
/usr/local/include/node/libplatform/v8-tracing.h
/usr/local/include/node/node.h
/usr/local/include/node/node_api.h
/usr/local/include/node/node_api_types.h
/usr/local/include/node/node_buffer.h
/usr/local/include/node/node_object_wrap.h
/usr/local/include/node/node_version.h
/usr/local/include/node/openssl/aes.h
/usr/local/include/node/openssl/asn1.h
/usr/local/include/node/openssl/asn1_mac.h
/usr/local/include/node/openssl/asn1t.h
/usr/local/include/node/openssl/bio.h
/usr/local/include/node/openssl/blowfish.h
/usr/local/include/node/openssl/bn.h
/usr/local/include/node/openssl/buffer.h
/usr/local/include/node/openssl/camellia.h
/usr/local/include/node/openssl/cast.h
/usr/local/include/node/openssl/cmac.h
/usr/local/include/node/openssl/cms.h
/usr/local/include/node/openssl/comp.h
/usr/local/include/node/openssl/conf.h
/usr/local/include/node/openssl/conf_api.h
/usr/local/include/node/openssl/crypto.h
/usr/local/include/node/openssl/des.h
/usr/local/include/node/openssl/dh.h
/usr/local/include/node/openssl/dsa.h
/usr/local/include/node/openssl/dtls1.h
/usr/local/include/node/openssl/e_os2.h
/usr/local/include/node/openssl/ebcdic.h
/usr/local/include/node/openssl/ec.h
/usr/local/include/node/openssl/ecdh.h
/usr/local/include/node/openssl/ecdsa.h
/usr/local/include/node/openssl/engine.h
/usr/local/include/node/openssl/err.h
/usr/local/include/node/openssl/evp.h
/usr/local/include/node/openssl/hmac.h
/usr/local/include/node/openssl/idea.h
/usr/local/include/node/openssl/lhash.h
/usr/local/include/node/openssl/md4.h
/usr/local/include/node/openssl/md5.h
/usr/local/include/node/openssl/mdc2.h
/usr/local/include/node/openssl/modes.h
/usr/local/include/node/openssl/obj_mac.h
/usr/local/include/node/openssl/objects.h
/usr/local/include/node/openssl/ocsp.h
/usr/local/include/node/openssl/opensslconf.h
/usr/local/include/node/openssl/opensslv.h
/usr/local/include/node/openssl/ossl_typ.h
/usr/local/include/node/openssl/pem.h
/usr/local/include/node/openssl/pem2.h
/usr/local/include/node/openssl/pkcs12.h
/usr/local/include/node/openssl/pkcs7.h
/usr/local/include/node/openssl/rand.h
/usr/local/include/node/openssl/rc2.h
/usr/local/include/node/openssl/rc4.h
/usr/local/include/node/openssl/ripemd.h
/usr/local/include/node/openssl/rsa.h
/usr/local/include/node/openssl/safestack.h
/usr/local/include/node/openssl/seed.h
/usr/local/include/node/openssl/sha.h
/usr/local/include/node/openssl/srp.h
/usr/local/include/node/openssl/srtp.h
/usr/local/include/node/openssl/ssl.h
/usr/local/include/node/openssl/ssl2.h
/usr/local/include/node/openssl/ssl3.h
/usr/local/include/node/openssl/stack.h
/usr/local/include/node/openssl/symhacks.h
/usr/local/include/node/openssl/tls1.h
/usr/local/include/node/openssl/ts.h
/usr/local/include/node/openssl/txt_db.h
/usr/local/include/node/openssl/ui.h
/usr/local/include/node/openssl/whrlpool.h
/usr/local/include/node/openssl/x509.h
/usr/local/include/node/openssl/x509_vfy.h
/usr/local/include/node/openssl/x509v3.h
/usr/local/include/node/pthread-barrier.h
/usr/local/include/node/stdint-msvc2008.h
/usr/local/include/node/tree.h
/usr/local/include/node/uv-aix.h
/usr/local/include/node/uv-bsd.h
/usr/local/include/node/uv-darwin.h
/usr/local/include/node/uv-errno.h
/usr/local/include/node/uv-linux.h
/usr/local/include/node/uv-os390.h
/usr/local/include/node/uv-posix.h
/usr/local/include/node/uv-sunos.h
/usr/local/include/node/uv-threadpool.h
/usr/local/include/node/uv-unix.h
/usr/local/include/node/uv-version.h
/usr/local/include/node/uv-win.h
/usr/local/include/node/uv.h
/usr/local/include/node/v8-inspector-protocol.h
/usr/local/include/node/v8-inspector.h
/usr/local/include/node/v8-platform.h
/usr/local/include/node/v8-profiler.h
/usr/local/include/node/v8-testing.h
/usr/local/include/node/v8-util.h
/usr/local/include/node/v8-value-serializer-version.h
/usr/local/include/node/v8-version-string.h
/usr/local/include/node/v8-version.h
/usr/local/include/node/v8.h
/usr/local/include/node/v8config.h
/usr/local/include/node/zconf.h
/usr/local/include/node/zlib.h
/usr/local/share/doc/node/gdbinit
/usr/local/share/doc/node/lldb_commands.py
/usr/local/share/doc/node/lldbinit
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
/usr/local/lib/dtrace/node.d
USER-no-MacBook-Pro-2:nomadcoin user$ brew link node
Linking /usr/local/Cellar/node/10.3.0...
Error: Could not symlink include/node/android-ifaddrs.h
Target /usr/local/include/node/android-ifaddrs.h
already exists. You may want to remove it:
rm '/usr/local/include/node/android-ifaddrs.h'
To force the link and overwrite all conflicting files:
brew link --overwrite node
To list all files that would be deleted:
brew link --overwrite --dry-run node
USER-no-MacBook-Pro-2:nomadcoin user$ run node
bash: run: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node --force
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew install node --rf
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ brew install -rf node
Warning: node 10.3.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
USER-no-MacBook-Pro-2:nomadcoin user$ node install yarn
bash: node: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ npm install yarn
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ brew install yarn -g
Warning: yarn 1.7.0 is already installed and up-to-date
To reinstall 1.7.0, run `brew reinstall yarn`
USER-no-MacBook-Pro-2:nomadcoin user$ brew reinstall yarn
==> Reinstalling yarn
==> Downloading https://yarnpkg.com/downloads/1.7.0/yarn-v1.7.0.tar.gz
Already downloaded: /Users/user/Library/Caches/Homebrew/yarn-1.7.0.tar.gz
🍺 /usr/local/Cellar/yarn/1.7.0: 14 files, 4.2MB, built in 1 second
USER-no-MacBook-Pro-2:nomadcoin user$ yarn install
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ yarn init
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ ln -s /usr/bin/nodejs /usr/bin/node
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ sudo ln -s /usr/bin/nodejs /usr/bin/node
Password:
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ $ sudo apt-get install nodejs-legacy
bash: $: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ $ sudo brew install nodejs-legacy
bash: $: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ npm debug
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ nvm debug
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ sudo chown -R $USER /usr/local
chown: /usr/local: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$ npm --version
env: node: No such file or directory
USER-no-MacBook-Pro-2:nomadcoin user$ nvm --version
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ nvm install
bash: nvm: command not found
USER-no-MacBook-Pro-2:nomadcoin user$ ln -s /usr/local/Cellar/node /usr/bin/node
ln: /usr/bin/node: Operation not permitted
USER-no-MacBook-Pro-2:nomadcoin user$
Trynode -v to see whether you've installed node. I think your node not works.
nvm is the environment managment for node. If you are using nvm, you should brew install nvm, and use nvm install version-of-node-you-want-to-install to install node, and use nvm use the-version to let node works.
Whole install chain is:
brew install nvm, to install nvm, which is environment/version management for node.
nvm install 10.3.0, to install node and npm
npm install -g yarn, to install yarn
use node -v, npm -v, nvm -v, yarn -v to check if they all works.
Perform the below steps:
which node
sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/node (output of above step) /usr/bin/node
For me I realized that hooks don't work when opening through the launcher.
instead I opened SourceTree through the terminal by running this command:
/Applications/SourceTree.app/Contents/MacOS/Sourcetree
I had the same issue on Ubuntu when trying to updating my npm version by using:
sudo npm install -g npm
I've solved by doing the same without sudo:
npm install -g npm
If you already installed nvm or node before and it worked, I would suggest to try to refresh your bash startup file. For example source .bash_profile
There are multiple bash startup file sometimes, you can check which one contains the nvm environment export setting to locate it.
I created a Docker image:
$ docker build -t stephaneeybert/nodejs .
Sending build context to Docker daemon 2.56 kB
Step 1 : FROM debian
---> 1b088884749b
Step 2 : RUN apt-get clean && apt-get update
---> Using cache
---> b12133d6342f
Step 3 : RUN apt-get install -y curl
---> Using cache
---> 22dfb4882b12
Step 4 : RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
---> Using cache
---> 27f2fac45254
Step 5 : RUN . ~/.nvm/nvm.sh; nvm install stable
---> Using cache
---> 20d99d545755
Step 6 : RUN . ~/.nvm/nvm.sh; nvm use stable
---> Using cache
---> 9ec14efb2407
Step 7 : RUN . ~/.nvm/nvm.sh; npm install -g npm
---> Using cache
---> d264d38565f3
Step 8 : EXPOSE 9001
---> Using cache
---> 29e3589557e1
Step 9 : ENTRYPOINT /usr/bin/tail -f /dev/null
---> Using cache
---> 2ce499300fe1
Successfully built 2ce499300fe1
The image script is:
FROM debian
RUN apt-get clean && apt-get update
RUN apt-get install -y curl
# Installing nodesjs
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
RUN . ~/.nvm/nvm.sh; nvm install stable
RUN . ~/.nvm/nvm.sh; nvm use stable
RUN . ~/.nvm/nvm.sh; npm install -g npm
EXPOSE 9001
ENTRYPOINT ["/usr/bin/tail", "-f", "/dev/null"]
Then I run the container and open a bash shell:
$ docker run -d -p 127.0.0.1:9001:9001 --name nodejs stephaneeybert/nodejs
c6dddf0a5eb0f11c897f63910eb01f2868fe0f39a80e5e2a580ef3a82935b27b
[stephane#stephane-ThinkPad-X301 nodejs]
$ docker exec -it nodejs bash
root#c6dddf0a5eb0:/#
Once in there, I try to get the version:
root#c6dddf0a5eb0:/# npm -v
bash: npm: command not found
But npm is not found.
When typing the command nvm use stable in the interactive shell, it give the following error: N/A: version "N/A" is not yet installed.
I understand there is an alias against a non existant node version.
The nvm ls command shows:
root#60446f9286d0:/# nvm ls
N/A
node -> stable (-> N/A) (default)
iojs -> N/A (default)
The debugger has this to show:
root#60446f9286d0:/# nvm debug
nvm --version: v0.32.1
$SHELL: /bin/bash
$HOME: /root
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: none
which node:
which iojs:
which npm:
npm config get prefix: bash: npm: command not found
npm root -g: bash: npm: command not found
1- How come I need to source this script . ~/.nvm/nvm.sh; on each command?
2- Why is my Node package manager not found in the bash shell?
EDIT: I changed a bit the content of the Dockerfile file:
RUN curl -o-https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash \
&& . ~/.nvm/nvm.sh \
&& nvm install stable \
&& nvm alias default stable \
&& nvm use default
And building it now shows this:
Step 4 :RUN curl -o https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash && . ~/.nvm/nvm.sh && nvm install stable && nvm alias default stable && nvm use default
---> Running in 7d2c404135dd
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 10250 100 10250 0 0 18258 0 --:--:-- --:--:-- --:--:-- 18238
=> Downloading nvm as script to '/root/.nvm'
=> Appending source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="/root/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v7.2.0 (npm v3.10.9)
Creating default alias: default -> stable (-> v7.2.0 *)
default -> stable (-> v7.2.0 *)
Now using node v7.2.0 (npm v3.10.9)
---> ad960a4addbe
Removing intermediate container 7d2c404135dd
Step 5 : EXPOSE 9001
---> Running in df9284421302
---> 14d386f009fb
Removing intermediate container df9284421302
Step 6 : ENTRYPOINT /usr/bin/tail -f /dev/null
---> Running in fa2d71b6dfdf
---> d02c8e88eb7f
Removing intermediate container fa2d71b6dfdf
Successfully built d02c8e88eb7f
I can see it installed node v7.2.0 and is using it.
But when I log into the container with the command docker exec -it nodejs bash it does not see any node anywhere:
root#f8f2a32b462a:/# nvm --version
0.32.1
root#f8f2a32b462a:/# npm --version
bash: npm: command not found
root#f8f2a32b462a:/# echo $NVM_DIR
/root/.nvm
root#f8f2a32b462a:/# ls -l /root/.nvm
total 100
-rwxr-xr-x 1 root root 313 Nov 26 13:01 nvm-exec
-rw-r--r-- 1 root root 95660 Nov 26 13:01 nvm.sh
root#f8f2a32b462a:/# ls -l /root/.npm
ls: cannot access /root/.npm: No such file or directory
I changed the way I install Node and did it without the nvm tool:
RUN curl -sL https://deb.nodesource.com/setup_7.x | bash
RUN apt-get install -y nodejs
Now, when logging in the container, it can find the Node executable:
$ docker run -d -p 127.0.0.1:9001:9001 --name nodejs stephaneeybert/nodejs
f3a2f054934ef92a9b05486b6f6dbe53abd4390826c06d1b7a490d671d8e3422
[stephane#stephane-ThinkPad-X301 nodejs]
$ docker exec -it nodejs bash
root#f3a2f054934e:/# npm --version
3.10.9
Maybe, when I was using the nvm tool, I should have sourced the npm command in the client shell . ~/.nvm/nvm.sh npm --version.
For amazonlinux (Ubuntu Fedora) you can install it using yum like this inside the Dockerfile:
RUN curl -sL https://rpm.nodesource.com/setup_10.x | bash # for node version 10.x
RUN yum -y install nodejs
RUN node --version # optional to check that it worked
RUN npm --version # optional to check that it worked
Use docker build -t [name] [local_folder_like_dot]
Took me ages to google, don't know much about linux but it seems like every version is so different from the other. It's like google docker npm, use apt get nah doesn't work, figure out wth linux version amasonlinux is.. Ok called Fedora.. it has yum instead of apt.. ok .. you need to answer yes in the yum install, docker doesn't allow it just skips it then.. wth.. I can hackz0r it with | yes nah that just spams y forevah.. ok I canz killall nah not in Fedora.. okiz can yum installz without questionz askz??! -y
2h later and we have this :)
I am trying to execute this command using Ansible:
- name: install node v5.5.0
sudo: yes
shell: nvm ls-remote
environment:
http_proxy: http://17.99.193.229:3128
https_proxy: http://17.99.193.229:3128
I tried shell and command.
When using command: I got this error:
"[Errno 2] No such file or directory", "rc": 2"
When using shell: I got this error:
"fatal: [gocdagent-dev-01.rno.apple.com]: FAILED! => {"changed": true, "cmd": "nvm ls-remote", "delta": "0:00:00.016365", "end": "2016-05-16 18:26:07.259729", "failed": true, "rc": 127, "start": "2016-05-16 18:26:07.243364", "stderr": "/bin/sh: nvm: command not found", "stdout": "", "stdout_lines": [], "warnings": []}"
I can execute nvm command directly on the system. Why can't Ansible run nvm?
Nvm is not a binary, you have to load it first :
- name: install node v5.5.0
shell: . <NVM_DIR>/.nvm/nvm.sh && nvm ls-remote
environment:
http_proxy: http://17.99.193.229:3128
https_proxy: http://17.99.193.229:3128
Because you are running it as root (sudo: yes) in Ansible script. Make sure nvm is in root's PATH or give /full/path/to/nvm in shell command.
I chased my tail for hours on this one. Olivier Lecrivain headed me in the right direction. This solved it. This also gives you the ability to install multiple versions at the same time
- name: installing node versions using loop
become: yes
# Execute config files such as .profile (Ansible uses non-interactive login shells)
become_flags: -i
become_user: yourdesireduser
# $HOME will become yourdesireduser's home directory
shell: ". $HOME/.nvm/nvm.sh && nvm install {{item}}"
args:
chdir: "$HOME/.nvm/"
# not needed as it is created automatically through the nvm install command
# creates: "$HOME/.nvm/versions/node/v{{item}}"
loop:
- 14.18.3