I have Dockerfile that looks like this
FROM alpine:3.7
WORKDIR /home/tmp
RUN apk add autoconf && apk add py-pip && apk add python3 &&\
pip install --upgrade pip && pip install wheel
Originally I wanted to execute a .sh script on startup (via ENTRYPOINT) and immediately destroy the container. However as it failed to find the file I decided to do that manually.
I run container like this
docker run -it --rm -v c:/projects/mega-nz-sdk:/home/tmp mega_sdk_python
And it connects me to bash in the container.
In the list of files I can see the script I want to execute
/home/tmp # ls
Dockerfile compile.sh sdk-develop
/home/tmp #
However when I try to run it it cannot find the script
/home/tmp # ./compile.sh
/bin/sh: ./compile.sh: not found
/home/tmp #
What is the problem?
Script compile.sh looks like this
#!/bin/bash
cd sdk-develop
sh autogen.sh
./configure --disable-silent-rules --enable-python --disable-examples &&\
make
cd /bindings/python
python setup.py bdist_wheel
Ideally I would like to execute during instantiation of the container in order to have already configured container on startup (without need to run script each I run the container).
It seems in order to execute my .sh file I need to run it like this
sh compile.sh
So I added
CMD ["sh", "compile.sh"]
And I started to work (though failed with other errors like missing make etc. but that's due to missing packages in Alpine Linux itself so a separate matter).
Guess It is something to do with Alpine Linux itself. But I am not sure.
Alpine Linux is a very minimal distribution; it includes a minimal version of most Unix tools that conform to the POSIX specification, but no more. In particular it does not include GNU Bash.
Your script doesn't actually use any special Bash features, so it would be enough to change the first line of the script to run the default system Bourne shell
#!/bin/sh
Using the Alpine apk package manager to install bash would work too, but it's not necessary for what you're showing here.
Usually you'd run the sorts of "compile" commands you show during the course of building an image, not when the image starts up. I'd expect a much more typical Dockerfile to COPY the application source code and in then RUN the commands you show. That would happen just once, when you docker build the image, and not every time you want to run the packaged application.
you mounted the directory from your win host to the docker machine. I BELIEVE this is a permission problem - the file is not executable flagged.
Show detailed listing
# ls -lh
copy the folder to internal dir and add executable bit
cp /home/tmp /home/tmp2 -r
chmod +x /home/tmp2/*.sh
/home/tmp2/compile.sh
I have downloaded Node.js from this link, which points to this link when clicking the button:
https://nodejs.org/dist/v4.1.2/node-v4.1.2-linux-x64.tar.gz
As advice from the Ubuntu community on installing the tar.gz, the following steps are followed.
$ ./configure
$ make
$ [sudo] make install
The problem is the current file I have downloaded does not contain ./configure.
So how do I install this? Should I extract this to the usr/ folder?
My OS is Debian 8 (Jessie).
Should I include the Java package from Oracle? Is it safe to extract these files to the /usr folder?
You can download this file from the browser or from the console. The latter is shown below (note: the specific Node.js version might be different for you):
Example :
wget http://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.gz
sudo tar -C /usr/local --strip-components 1 -xzf node-v8.1.1-linux-x64.tar.gz
#tar options:
-x, --extract, --get
extract files from an archive
-f, --file ARCHIVE
use archive file or device ARCHIVE
-z, --gzip, --gunzip --ungzip`
You may find list of node version on http://nodejs.org/dist/
You should now have both Node.js and npm installed in “/usr/local/bin”. You can check this typing:
ls -l /usr/local/bin/node ls -l /usr/local/bin/npm
*An alternative way to install Node.js via the package manager:
Installing Node.js via package manager
Download the .tar.xz file form https://nodejs.org/en/ and then press Ctrl + Alt + T.
Then go to the destination that you downloaded your file to. For me it's my downloads folder. Then hit this command and Node.js will get installed on your system:
sudo tar -xf node-v16.0.0-linux-x64.tar.xz --directory=/usr/local --strip-components=1
This was the answer I had posted over two years ago, and here is what I recommand you right now, decompress the tarball, and keep it anywhere where your system knows ( tell it via updating $PATH ), its just a binary file, its not necessary to keep it in some specific location, you can keep it in your home directory and andd your bin folder to your bashrc or whatever shell you are using, its .rc file, and it will work just fine, at the end of the day, its just a pre-compiled binary file (inside node) nothing much.
Somebody in the comment section was saying npm, needs to be installed sepretly, this was in the early days of node back in 2012, when npm used to not ship with node, if you look inside bin folder npm binary is also there, so you dont need to install npm sepretly.
In case of installing from source code, you must download source code from https://nodejs.org/dist/v4.1.2/node-v4.1.2.tar.gz.
The file ending with .tar.gz is the compressed file like zip file, and you should extract the file before you can do another operation.
You can extract this file anywhere you need. In the terminal, change the location to your .tar.gz file:
$ cd /path/to/tar.gz/file
Then extract it using tar:
$ tar xvzf node-v4.1.2.tar.gz
Then change the location to the extracted directory
$ cd node-v4.1.2
After this, you can run .configure and 'make' it:
$ ./configure
$ make
$ [sudo] make install
Using the make utility is only necessary if you're compiling software. However, the tarballs provided by nodejs.org contain compiled binaries, not source code. Really you don't need to install it to use.
You can simply cd into the bin directory and run it via ./node. Though I'll say it's pretty useful to have it in your PATH. Where you put this directory doesn't really matter.
If you're installing it locally on your own machine, you can just untar it, tar xvfz node*tar.gz, to your home directory, add this to the file ~/.bashrc, and append the directory path your your PATH environment variable like so PATH=$PATH:/home/USERNAME/DIRECTORY/bin. Just change the path to the exact path to the bin folder in the directory you extracted.
You can also add these files to a directory that's already in your path, such as /usr/share or /usr/local by simple copying the files from the archive into these folders, as they share the same structure.
Run the following commands where your ta.xz file (no need for extraction) file is located in the terminal. NB: I used Kali Linux
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-v14.4.0-linux-x64.tar.xz -C /usr/local/lib/nodejs
export PATH=/usr/local/lib/nodejs/node-node-v14.4.0-linux-x64/bin:$PATH
You can now check npm -v, node -v, and npx -v.
STEP 1:
Download your version of Node.js from the Node.js website or use the below command with your version:
wget http://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.gz
You will get a Node.js file tar file after the above step.
STEP 2:
Just use the below command for installation
sudo tar -C /usr/local --strip-components 1 -xvf node-v8.1.1-linux-x64.tar.gz
I am mentioning version-specific installation of NVM and Node.js.
If you don't have brew installed, run this:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
If you don't have wget installed, run this:
brew install wget
To install Node.js of a specific version, run these commands: Here, I'm installing NVM - v0.33.1 and Node.js of v0.12.6.
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
source ~/.bashrc
nvm install v0.12.6
command -v nvm //verify install
You can do some this:
# Using Ubuntu or Debian
curl -sL https://deb.nodesource.com/setup_[version].x | sudo -E bash -
sudo apt-get install -y nodejs
Where [version] must be replaced for your version of Node.js that you required install
For example, I required to install Node.js v.12
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
Download a suitable installation from
https://nodejs.org/en/download/
Incase of CentOS
Go to the downloaded file location
Execute the following
sudo tar -C /usr/local --strip-components 1 -xf "name of the tar.xz downloaded"
Check the installed version is correct
node --version
The given solution is correct, but it works for the source file and not the Linux distribution link used in the question above.
$ ./configure
$ make
$ [sudo] make install
The correct link is: https://nodejs.org/dist/v8.11.2/node-v8.11.2.tar.gz and we can use the above steps after downloading and extracting this file.
Download the latest version of Node.js from the official site, https://nodejs.org/en/
Steps to install:
Extract to any of the directories where you wish to install Node.js using a command or archive manager window
Open the terminal
Run '$sudo su'
Being superuser and open the profile file using 'nano ~/.profile'
At the end of the file, add:
# Node.js
export PATH=/path-to-bin.executable:$PATH
The path to bin application located within the bin folder of Node.js extracted folder is to be pasted in the above line
Save using Ctrl + O then come out by Ctrl + X
Refresh profile by the command '.~/.profile'
Come out of superuser by the 'exit' command
Again for normal users, use 'sudo'
'sudo nano ~/.profile'
Add the line at the end:
# Node.js
export PATH=/path-to-bin.executable:$PATH
Same as in step 5
Save and exit
Here the refresh command as above won't work, so restart the system to finish installation correctly
To get the version, issue 'node -v'
I just fired up a new EC2 instance on Amazon and I'm trying to install nvm. I tried running their install script with the NVM_DIR=... for a global install:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | NVM_DIR=/usr/local/nvm bash
but I get this error:
=> Downloading nvm from git to '/usr/local/nvm'
=> mkdir: cannot create directory ‘/usr/local/nvm’: Permission denied
I get this error with sudo as well. I also tried going into usr/local and making the nvm directory manually, but then i get other errors like this:
=> Cloning into '/usr/local/nvm'...
/usr/local/nvm/.git: Permission denied
Does anyone know why this is happening? Is it a permissions thing on aws I am unfamiliar with?
Edit: using a much older version without the NVM_DIR stuff worked. I still want global access though, so this does not solve the problem
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
Your normal user won’t have access to write to /usr/local, so you’ll need to run the install script as root/sudo.
Your curl command is fine to run as your user. In fact, it’s best to just curl the file to a local location before running it, so you can eyeball it -- unless you have reason to believe it is a very trustworthy script. So grab the install.sh script:
% curl -O https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh
% $EDITOR install.sh # feel free to look it over
Then install it with sudo:
% sudo -i # become root temporarily
# export NVM_DIR=/usr/local/nvm # set the environment variable
# bash install.sh # run installer as root
# exit
%
(There is a way to make the whole installation a one-liner, passing the environment variable through sudo, but I don't think it's necessary, and a little more complex, IMHO.)
I'm trying to install dnvm on an Ubuntu VM using Vagrant. In my vagrantfile I have a shell script that includes this line:
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source /root/.dnx/dnvm/dnvm.sh
which downloads and executes dnvminstall.sh which installs and puts dnvm.sh in /root/.dnx/dnvm. The source /root/.dnx/dnvm/dnvm.sh part doesn't seem to have worked because when I ssh into the machine I need to run it manually for dnvm to work.
So the question is, why isn't source /root/.dnx/dnvm/dnvm.sh executed during provisioning?
Here's the vagrantfile in it's entirety.
You're cding into /usr/local/src/libuv-1.4.2 earlier in your script.
Then you're downloading dnvm into that directory using curl, then trying to run the file as if it was in /root/.dnx/dnvm/dnvm.sh, when it's actually somewhere under /usr/local/src/libuv-1.4.2
You just need to cd back into /root before you use curl to get dnvm. So ...
cd /root
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source /root/.dnx/dnvm/dnvm.sh
Hope this helps!
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.