How to install awscli on any linux flavor without having to install python first - aws-cli

I need to build a script that would install awscli on any Linux flavor. I can't expect that python is present on a machine, and the ways to install python on various flavors of Linux differs. How can I install awscli without installing python first?

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "/tmp/awscli-bundle.zip"
unzip /tmp/awscli-bundle.zip -d /tmp/
sudo /tmp/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

You can also use the distribution's package manager; though you risk obtaining an older version of awscli.

Related

Alpine 3.11 diff: unrecognized option: c BusyBox v1.31.1 () multi-call binary

I am using an alpine 3.11 to build my image, everything goes well during the build the dockefile is here below :
FROM alpine:3.11
LABEL version="1.0"
ARG UID="110"
ARG PYTHON_VERSION="3.8.10-r0"
ARG ANSIBLE_VERSION="5.0.1"
ARG AWSCLI_VERSION="1.22.56"
# Create jenkins user with sudo privileges
RUN adduser -u ${UID} -D -h /home/jenkins/ jenkins
RUN echo 'jenkins ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN mkdir -p /tmp/.ansible
RUN chown -R jenkins:jenkins /tmp/.ansible
# Install minimal packages
RUN apk --update --no-cache add bash bind-tools curl gcc git libffi-dev libpq make mysql-client openssl postgresql-client sudo unzip wget coreutils
#RUN apk --update --no-cache add py-mysqldb
RUN apk --update --no-cache add python3=${PYTHON_VERSION} python3-dev py3-pip py3-cryptography
# Install JQ from sources
RUN wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
RUN mv jq-linux64 /usr/bin/jq
RUN chmod +x /usr/bin/jq
# Install ansible and awscli with python package manager
RUN pip3 install --upgrade pip
RUN pip3 install yq --ignore-installed PyYAML
RUN pip3 install ansible==${ANSIBLE_VERSION}
RUN pip3 install awscli==${AWSCLI_VERSION} boto boto3 botocore s3cmd pywinrm pymysql 'python-dateutil<2.8.1'
# Clean cache
RUN rm -rf /var/cache/apk/*
# Display packages versions
RUN python3 --version && \
pip3 --version && \
ansible --version && \
aws --version
this image is later used to lunch some jenkins jobs nothing unusual.
But when i try to use the diff command in of these jobs I have the following error :
diff: unrecognized option: c BusyBox v1.31.1 () multi-call binary
that's why i tried to install the coreutils package but still the "-c" option is still unrecognized which is weird.
So my question is there a way to add the -c option for the diff command because in the manual of GNU this should be available automatically but apparently not on Alpine ? if there is a way could anyone please share it.
P.S : In case you are wondering why am I using the diff command it is just to compare two json files and the -c is necessary for me in this context.
Well I just had to add the diffutils package to the list after installing it everything works well
In spite of it being required in the POSIX diff specification it looks like the BusyBox implementation of diff doesn't support the -c option.
One thing you could do is change your diff invocation to use unified context diff format. Again, BusyBox diff appears to not support -u, so you need to use an explicit -U option with the number of lines of context
diff -U3 file.orig file.new
In general, the Alpine environment has many small differences like this. If you're installing the GNU versions of these tools anyways – your Dockerfile already installs GNU bash and coreutils – you'll probably find minimal to no space savings from using an Alpine base image, and using a Debian or Ubuntu base that already includes the GNU versions of these tools will be easier.
FROM ubuntu:20.04 # not Alpine
...
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
bind9-utils \
build-essential \
curl \
git-core \
...
You may need to search on https://packages.debian.org/ to find equivalent Debian packages. build-essential is a metapackage that includes the entire C toolchain (gcc, make, et al.); bash, coreutils, and diffutils would typically be installed as part of the base distribution image.

How to install python version 3.5.6 into ubuntu/ Linux?

I need to install python version 3.5.6. What are the requirements to install python 3.5.6.
python 3.6 is already installed on my local machine
What I have tried?
I looked into Python downloads. Downloaded tarball for python3.5.6.
Installed it by using following set of commands
wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tar.xz
tar -xf Python-3.5.6.tar.xz
cd Python-3.5.6
sudo apt-get install libbz2-dev libsqlite3-dev build-essential
./configure
make
sudo make install
After installation when I run python3 -V it shows python 3.6.
Expected behaviour
python3 -V command should show python3.5.6
What I am doing wrong?
Try uninstalling it or removing the package all together from your computer. Afterwards try:
$ sudo apt-get install --reinstall python3.5
or you could try:
$ sudo aptitude reinstall python2.7
Best of luck.
python3.5 might show 3.5.6, depending on where and how things are on your PATH.
Either way, instead of manually compiling and installing Python (especially as you're side-stepping your package manager (apt) here which may cause trouble down the line), look into pyenv. After installation, approximately:
$ pyenv install 3.5.6
$ pyenv local 3.5.6
$ python
and you're ready to roll.

How to upgrade AWS CLI to the latest version?

I recently noticed that I am running an old version of AWS CLI that is lacking some functionality I need:
$aws --version
aws-cli/1.2.9 Python/3.4.3 Linux/3.13.0-85-generic
How can I upgrade to the latest version of the AWS CLI (1.10.24)?
Edit:
Running the following command fails to update AWS CLI:
$ pip install --upgrade awscli
Requirement already up-to-date: awscli in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Checking the version:
$ aws --version
aws-cli/1.2.9 Python/3.4.3 Linux/3.13.0-85-generic
From http://docs.aws.amazon.com/cli/latest/userguide/installing.html#install-with-pip
To upgrade an existing AWS CLI installation, use the --upgrade option:
pip install --upgrade awscli
On Linux and MacOS X, here are the three commands that correspond to each step:
$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
$ unzip awscli-bundle.zip
$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
This does not work:
pip install --upgrade awscli
This worked fine on Ubuntu 14.04( no need to reboot also .. You would have to first install pip3 ):
pip3 install --upgrade awscli
For Ubuntu 16.04 I used parts of the other answers and comments and just reloaded bash instead of rebooting.
I installed the aws-cli using apt so I removed that first:
sudo apt-get remove awscli
Then I could pip install (I chose to use sudo to install globally with pip2):
sudo pip install -U awscli
Since I was doing this on a server I didn't want to reboot it, but reloading bash did the trick:
source ~/.bashrc
At this point I could use the new version of aws cli
aws --version
Update: Upgrade instance using AWS CLI v1 to AWS CLI v2:
This question and answer was initially created when there was only an AWS CLI v1. There is now a AWS CLI v2. The installation instructions for the AWS CLI v2 can be found here.
The new AWS CLI v2 has different installation instructions based on whether your EC2 instance is using Linux x86 (64-bit) or Linux ARM architecture.
To upgrade to AWS CLI v2, on an EC2 instance using Linux ARM, I had to issue the following commands:
rm -rf /bin/aws
curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install -i /usr/local/aws -b /bin
Subsequently test your AWS CLI version by executing: aws --version
For the Linux x86 (64-bit) architecture I'm hoping the commands are the same except for replacing the curl command with the following: (as per the installation instructions)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o
"awscliv2.zip"
The AMI I used was the most recent one currently available and it was still using the AWS CLI v1. In the future if AWS starts packaging AWS CLI v2 with their AMIs this answer might require an update.
Original answer: Upgrade instance using AWS CLI v1 to use the most recent version of AWS CLI v1:
If you are having trouble installing the AWS CLI using pip you can use the "Bundled Installer" as documented here.
The steps discussed there are as follows:
$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
$ unzip awscli-bundle.zip
$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Check your AWS CLI version subsequently as a sanity-check that everything executed correctly:
$ aws --version
If the AWS CLI didn't update to the latest version as expected maybe the AWS CLI binaries are located somewhere else as the previously-given commands assume.
Determine where AWS CLI is being executed from:
$ which aws
In my case, AWS CLI was being executed from /bin/aws, so I had to install the
"Bundled Installer" using that location as follows:
$ sudo ./awscli-bundle/install -i /user/local/aws -b /bin/aws
Try
sudo pip install --upgrade awscli, and open a new shell.
This worked well for me (no need to reboot).
Simple use
sudo pip install awscli --force-reinstall --upgrade
This will upgrade all the required modules.
On Mac you can use homebrew:
to install: brew install awscli
to upgrade: brew upgrade awscli
Make sure you don't have multiple installations: where aws
pip install awscli --upgrade --user
The --upgrade option tells pip to upgrade any requirements that are already installed. The --user option tells pip to install the program to a subdirectory of your user directory to avoid modifying libraries used by your operating system.
We can follow the below commands to install AWS CLI on UBUNTU:
sudo apt install curl
curl “https://s3.amazonaws.com/aws-cli/awscli-bundle.zip” -o
“awscli-bundle.zip”
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/ aws -b /usr/local/bin/aws
rm -rf awscli-bundle.zip awscli-bundle
To test: aws — version
For More Info :
https://gurudathbn.wordpress.com/2018/03/31/installing-aws-cli-on-ubuntu/
When using sudo pip install --upgrade awscli I got the following error:
ERROR: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system: '/lib'
By using sudo with -H option, I could fix the problem.
sudo -H pip install --upgrade awscli
Currently, using pip will get you the old version of awscli, 1.18.103.
The latest version of aws-cli, 2.0.33 is on the v2 branch. You can download the installer for Linux, Windows and macOS from here.
I was trying to install awscli on one of my ec2 instances where I tried both
sudo pip install --upgrade awscli,
sudo pip3 install --upgrade awscli
which didn't worked, as I was getting errors like
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-2nh71cs2/cryptography/
And rebooting servers were not an option.
Luckily, simple
sudo apt update
sudo apt install awscli worked.
I do it by removing & installing the awscli like described in this video
basically:
pip uninstall awscliv2
pip install awscliv2
pip install awscliv2==your-version
pip install awscliv
(you can keep v1 along with v2 if you want)
pip install --upgrade ...
works as well. sure.
I do not install it globally (like some ppl seems still do), btw. Because sometimes I need different v for different cases. so I keep it in separate python virtual environment.
For windows you can try this command
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
Install or update the AWS CLI on macOS
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg ./AWSCLIV2.pkg -target /
Done!
You can verify the same with below cmd
aws --version
Try AWS Cloud Shell, Quick and easy
AWS CloudShell is a browser-based shell that makes it easy to securely manage, explore, and interact with your AWS resources. CloudShell is pre-authenticated with your console credentials.
Benefits
No extra credentials to manage
Always up to date
No cost
More Details here https://aws.amazon.com/cloudshell/
Customizable
To install globally, get on the sudo access
sudo su & then upgrade aws cli by
pip3 install --upgrade awscli

Nodejs installed without npm?

I've just installed nodejs on Debian 7 - by apt-get install nodejs.
Nodejs seems to be working fine, but when I enter "npm" I get "command not found".
"which nodejs" points to "usr/bin" and there it is - nodejs, but there is no npm file, what went wrong?
I found a few solutions, but all of them are related to Macs
BTW, "usr/local/bin" directory is empty I believe everything should install right there?
You have several options.
If you want to continue using Debian packages, you could install npm (debian maintainers have it in a separate package).
apt-get install npm
If you want to just install npm, you can use this modification of Maxime's answer:
curl -L https://npmjs.org/install.sh | sudo sh
(the -L is needed to make curl follow redirects.)
Finally, you may wish to use a different package source.
For some Linux distributions (Debian/Ubuntu and RedHat/CentOS), the latest node version provided by the distribution may lag behind the stable version. Here are instructions from NodeSource on getting the latest node, which includes npm and avoids using the problematic nodejs alias
Install npm
curl -L https://npmjs.org/install.sh | sudo sh
(the -L is needed to make curl follow redirects.)
and check version
npm -v
Node.js is easy to install in Linux
create a directory nodejs inside /usr/local/lib
download nodejs
move downloaded tar.xz file inside /usr/local/lib
extract the tar.xz file and rename as like node-v8.9.4
setup environment
cd ./etc/profile.d
ls
sudo touch nodejs-env.sh
sudo atom nodejs-env.sh
where atom is my favourite editor; you can use your editor.
copy and paste below code inside nodejs-env.sh and save
export NODEJS_HOME=/usr/local/lib/nodejs/node-v8.9.4
export PATH=$NODEJS_HOME/bin:$PATH
restart you machine.
done
There were several methods to install node.js on your debian. But I prefer this one:
Setup with Debian (as root):
apt-get install curl
curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
Then install with Debian (as root):
apt-get install --yes nodejs
After that, relaunch your terminal and type "npm" in your terminal.
The problem you're facing is due the need of super user rights during the installation. As others mentioned, you could do it via the sudo command and the manual installer.
Either way, there're several ways to install node in *unix platforms in a safer way without the need of super user rights using NVM (Node Version Manager).
Steps:
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
$ nvm install 0.10
Also, you can find different techniques to install node and npm without having to sudo.

How to install a specific version of Node on Ubuntu?

I would like to install NodeJS version 0.8.18 on Ubuntu 12.04. I tried to install the newest version and then reverting to 0.8.18 by using nvm, but when I run my code apparently there is some problem with the packages installed and the two versions (latest and 0.8.18). Since I don't know how to solve that problem, I cleaned the machine from the Node installation and thought about installing directly the version I'm interested in (v0.8.18).
The n module worked for me.
Run this code to clear npm’s cache, install n, and install the latest stable version of Node:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
See: http://www.hostingadvice.com/how-to/update-node-js-latest-version/
And: https://www.npmjs.com/package/n
To install a specific version of node:
sudo n 6.11.2
To check what version:
node -v
You might need to restart
Chris Lea has 0.8.23 in his ppa repo.
This package let you add a repository to apt-get: (You can also do this manually)
sudo apt-get install software-properties-common
Add Chris Lea's repository:
sudo apt-add-repository ppa:chris-lea/node.js-legacy
Update apt-get:
sudo apt-get update
Install Node.js:
sudo apt-get install nodejs=0.8.23-1chl1~precise1
I think (feel free to edit) the version number is optional if you only add node.js-legacy. If you add both legacy and ppa/chris-lea/node.js you most likely need to add the version.
NVM (Node Version manager)
https://github.com/nvm-sh/nvm
Advantages:
allows you to use multiple versions of Node and without sudo
is analogous to Ruby RVM and Python Virtualenv, widely considered best practice in Ruby and Python communities
downloads a pre-compiled binary where possible, and if not it downloads the source and compiles one for you
Tested in Ubuntu 17.10:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9
For the particular case of the most recent long term support version (recommended if you can choose):
nvm install --lts
nvm use --lts
npm --version
npm install --global vaca
vaca
Since the sourcing has to be done for every new shell, the install script hacks adds some auto sourcing to the end of your .barshrc. That works, but I prefer to remove the auto-added one and add my own:
f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
. "$f" &>'/dev/null'
nvm use --lts &>'/dev/null'
fi
With this setup, you get for example:
which node
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/node
and:
which vaca
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/vaca
and if we want to use the globally installed module:
npm link vaca
node -e 'console.log(require.resolve("vaca"))'
gives:
/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.js
as mentioned at:
NodeJS require a global module/package
How do I import global modules in Node? I get "Error: Cannot find module <module>"?
so we see that everything is completely contained inside the specific node version.
For projects however, you are better off just using packages installed locally under node_modules and npx for executable to be able to have independent versions across projects, global usage is mostly for the Node executable itself and global CLI utilities not specific to any project.
Setting the NPM version
Simply:
npm install npm#6.14.13 -g
The executable is placed inside the current NVM version, so everything remains nice and isolated, e.g.:
which npm
gives something like:
/home/ciro/.nvm/versions/node/v14.17.0/bin/npm
How can I change the version of npm using nvm?
It is possible to install specific version of nodejs from nodejs official distribution with using dpkg.
Check the version of you ubuntu distribution, cat /etc/lsb-release.
Check architecture of your os, uname -m.
Download preferred version of debian package from nodejs official site.
For 4.x, https://deb.nodesource.com/node_4.x/pool/main/n/nodejs/
For 5.x, https://deb.nodesource.com/node_5.x/pool/main/n/nodejs/
For 0.12.x, https://deb.nodesource.com/node_0.12/pool/main/n/nodejs/
Be careful to check nodejs-dbg or nodejs in filename.
For example, currently recent 4.x version is 4.2.4, but you can install previous 4.2.3 version.
curl -s -O https://deb.nodesource.com/node_4.x/pool/main/n/nodejs/nodejs_4.2.3-1nodesource1~trusty1_amd64.deb
sudo apt-get install rlwrap
sudo dpkg -i nodejs_4.2.3-1nodesource1~trusty1_amd64.deb
Try this way. This worked me.
wget nodejs.org/dist/v0.10.36/node-v0.10.36-linux-x64.tar.gz(download file)
Go to the directory where the Node.js binary was downloaded to, and then run command i.e, sudo tar -C /usr/local --strip-components 1 -xzf node-v0.10.36-linux-x64.tar.gz to install the Node.js binary package in “/usr/local/”.
You can check:-
$ node -v
v0.10.36
$ npm -v
1.4.28
In ubuntu specific version of node can be installed with help of nvm
install nvm
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
To install a particular version of node, use the command nvm install and add the number of the version.
nvm install 10.15.2
node -v
Say you want to install Node 10,
Firstly, download and execute the Node.js 10.x installer:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
This will add a source file for the official Node.js 10.x repo, grabs the signing key
Once the installer is done doing it’s thing, you will need to install (or upgrade) Node.js:
sudo apt install nodejs
version 0.10 is also avaible with this ppa
apt-add-repository ppa:chris-lea/node.js
install nodejs with:
apt-get install nodejs=0.10.25-1chl1~precise1
Thanks to my friend Julian Xhokaxhiu
I imagine many directed here are looking for this to add to a Dockerfile
RUN set -x \
&& curl -sL 'https://deb.nodesource.com/setup_16.x' | bash - \
&& apt-get -y install nodejs \
&& ln -s /usr/bin/nodejs /usr/local/bin/node
FYI, according to this page in the wiki of the nodejs github repo, Chris Lea's PPA (mentioned in several other answers) has been superseded by the NodeSource distributions as the main way of installing nodejs from source in Ubuntu:
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
This is supported for the three latest (at the time of writing this) LTS versions of Ubuntu: 10.04 (lucid), 12.04 LTS (precise) and 14.04 (trusty).
I'm not sure this will help in installing an old version of nodejs, but I'm putting this here in case it helps others who needed to install a specific (newer) version of nodejs that isn't included in their distro's repositories.
yes, its a duplicate answer but I insist using n module to install a specific version(following commands installs node version 6.9.5).
npm install -g n
n 6.9.5
NOTE: you can use NVM software to do this in a more nodejs fashionway.
However i got issues in one machine that didn't let me use NVM. So i
have to look for an alternative ;-)
You can manually download and install.
go to nodejs > download > other releases
http://nodejs.org/dist/
choose the version you are looking for
http://nodejs.org/dist/v0.8.18/
choose distro files corresponding your environmment and download (take care of 32bits/64bits version).
Example: http://nodejs.org/dist/v0.8.18/node-v0.8.18-linux-x64.tar.gz
Extract files and follow instructions on README.md :
To build:
Prerequisites (Unix only):
* Python 2.6 or 2.7
* GNU Make 3.81 or newer
* libexecinfo (FreeBSD and OpenBSD only)
Unix/Macintosh:
./configure
make
make install
If your python binary is in a non-standard location or has a
non-standard name, run the following instead:
export PYTHON=/path/to/python
$PYTHON ./configure
make
make install
Windows:
vcbuild.bat
To run the tests:
Unix/Macintosh:
make test
Windows:
vcbuild.bat test
To build the documentation:
make doc
To read the documentation:
man doc/node.1
Maybe you want to (must to) move the folder to a more apropiate place like /usr/lib/nodejs/node-v0.8.18/ then create a Symbolic Lynk on /usr/bin to get acces to your install from anywhere.
sudo mv /extracted/folder/node-v0.8.18 /usr/lib/nodejs/node-v0.8.18
sudo ln -s /usr/lib/nodejs/node-v0.8.18/bin/node /usr/bin/node
And if you want different release in the same machine you can use debian alternatives. Proceed in the same way posted before to download a second release. For example the latest release.
http://nodejs.org/dist/latest/ -> http://nodejs.org/dist/latest/node-v0.10.28-linux-x64.tar.gz
Move to your favorite destination, the same of the rest of release you want to install.
sudo mv /extracted/folder/node-v0.10.28 /usr/lib/nodejs/node-v0.10.28
Follow instructions of the README.md file. Then update the alternatives, for each release you have dowload install the alternative with.
sudo update-alternatives --install genname symlink altern priority [--slave genname symlink altern]
Add a group of alternatives to the system. genname is the
generic name for the master link, symlink is the name of its
symlink in the alternatives directory, and altern is the
alternative being introduced for the master link. The arguments
after --slave are the generic name, symlink name in the
alternatives directory and alternative for a slave link. Zero
or more --slave options, each followed by three arguments, may
be specified.
If the master symlink specified exists already in the
alternatives system’s records, the information supplied will be
added as a new set of alternatives for the group. Otherwise, a
new group, set to automatic mode, will be added with this
information. If the group is in automatic mode, and the newly
added alternatives’ priority is higher than any other installed
alternatives for this group, the symlinks will be updated to
point to the newly added alternatives.
for example:
sudo update-alternatives --install /usr/bin/node node /usr/lib/nodejs/node-v0.10.28 0 --slave /usr/share/man/man1/node.1.gz node.1.gz /usr/lib/nodejs/node-v0.10.28/share/man/man1/node.1
Then you can use update-alternatives --config node to choose between any number of releases instaled in your machine.
To install a specific version of nodejs in Ubuntu you can use below commands, just specify and replace the version number, for example, node_12.x will fetch the latest of 12.
curl https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install nodejs
FYI the available version for raring in Chris Lea's repo is currently 0.8.25
sudo apt-get install nodejs=0.8.25-2chl1~raring1
The Node.js project recently pushed out a new stable version with the 0.10.0 release
Use the following command on Ubuntu 13x
sudo apt-get install nodejs=0.10.18-1chl1~raring1
Install nvm using the following commands in the same order.nvm stands for node version manager.
sudo apt-get update
sudo apt-get install build-essential checkinstall libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
In case the above command does not work add -k after -o- .It should be as below:
curl -o- -k https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
Then nvm ls-remote to see the available versions.
In case you get N/A in return,run the following.
export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
alternatively you can run the following commands too
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
Then nvm install #.#.# replacing # by version(say nvm 8.9.4)
finally nvm use #.#.#
Here is a list of available builds for debian: https://github.com/nodesource/distributions/tree/master/deb
For this example, lets assume you want version 14 (LTS at the time of writing)
We can download this script from github, execute it and install the version of node we want. For security reasons it's a good idea to read the script prior to executing it.
curl -sL https://raw.githubusercontent.com/nodesource/distributions/master/deb/setup_14.x | bash
apt-get install -y nodejs # may or may not require sudo based on your setup
I like this approach because it doesn't require extraneous dependencies like nvm to target specific versions
If you are building for a different distro or architecture you can find more builds here https://nodejs.org/dist/

Resources