Issue
I have on AWS EC2
instance. When I install Node.js
with this
href="https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html" rel="nofollow noreferrer">AWS tutorial all works fine until i logout current session and log in, than Node.js
and Yarn
are gone. There is also note from AWS
:
The node installation only applies to the current Amazon EC2 session. If you restart your CLI session you need to use nvm to enable the installed node version. If the instance is terminated, you need to install node again. The alternative is to make an Amazon Machine Image (AMI) of the Amazon EC2 instance once you have the configuration that you want to keep, as described in the following topic.
Is it possible to install Node.js
so it is available in another session? I installed zsh and that works for all sessions.
I also created simple script that will install Node.js
and Yarn
. Commands in this script are from AWS
Tutorial page that I mentioned early. It will install Node.js
and Yarn
, show that all works (it shows Yarn
version and message from node command), but when I type npm --version
or yarn --version
it will shows message zsh: command not found: yarn (or similar message for npm).
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install --lts
node -e "console.log('Running Node.js ' + process.version)"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
echo "installing YARN !!!!! "
npm install yarn --global
Why is my script not working?
Solution
If you use manual from AWS how to install Node.js than instalation is only made in your home directory that lives only for current session. To install Node.js and Yarn I used this post: https://stackoverflow.com/a/35165401/78935
Or you could simply use this:
sudo curl --silent --location https://rpm.nodesource.com/setup_16.x | bash
sudo yum -y install nodejs
sudo npm install yarn --global
yarn --version
Answered By - Pavel Kostal Answer Checked By - Katrina (WPSolving Volunteer)