I am running a debian VM Instance using GCP Compute Engine and I have added a automation script to be executed on startup.
There are few tools which will be downloaded on startup. Only issue is, everything is getting downloaded in / directory.
I need to download everything in $HOME directory.
Different ways I have tried
#!/bin/bash
set -x
cd $HOME
mkdir $HOME/test
cd $HOME/test
apt install wget -y
wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz
#!/bin/bash
set -x
source $HOME
mkdir $HOME/something
#!/bin/bash
set -x
cd $HOME
mkdir $HOME/something
exec bash
Still it is downloaded in / directory. What else can be done here?
You are trying to make 2 things : install wget package and download another one.
Why don't you tried to install wget manually ?
apt-get install wget
You have then to store the full path for your script, and download the package needed it it. Try this :
#!/bin/bash
homePath=$HOME
mkdir $HOME/test
wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz -P $homePath/test/
To permanently update ~/.profile with source, only working on manual input. Also reboot of the whole system won‘t update ~/.profile and i need to update it manual.
Is there a special code style to use it as working code inside a bash/shell script or is this special code not intended to be used in automated scripts?
Need it to automate installation of golang.
In the following code the line "source ~/.profile" won't work, and without any error messages, the rest is working fine:
#!/bin/bash
sudo apt update
sudo apt -y upgrade
cd ~
curl -O https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
tar xvf go1.12.5.linux-amd64.tar.gz
sudo chown -R root:root ./go
sudo mv go /usr/local
cd ~
sudo rm go1.12.5.linux-amd64.tar.gz
sudo echo "export GOPATH=\$HOME/work" >> ~/.profile
sudo echo "export PATH=\$PATH:/usr/local/go/bin:\$GOPATH/bin" >> ~/.profile
source ~/.profile
Preferred:
Source the script itself rather than running it - then the commands in the script are run in the current shell, including the source ~/.profile.
Alternative (since this replaces the running shell, history, variable values, and other state will be lost. So there should be a very good reason to use this method):
Use exec bash or something similar instead of source ~/.profile - this replaces the currently running Bash with another instance which will itself load the new .profile.
Here is a refactoring which defers the decision to the user and cleans up the script somewhat.
#!/bin/bash
# Put this in a variable so there is only one place to update
tarball='go1.12.5.linux-amd64.tar.gz'
sudo apt update
sudo apt -y upgrade
# cd || why would you?
curl -O "https://dl.google.com/go/$tarball"
tar xvf "$tarball"
sudo chown -R root:root ./go
sudo mv go /usr/local
rm "$tarball"
printf '%s\n' "export GOPATH=\$HOME/work" \
"export PATH=\$PATH:/usr/local/go/bin:\$GOPATH/bin" >> ~/.profile
echo "$0: done. source ~/.profile or exec bash to activate new settings." >&2
I am trying to set the default python in my docker container to be python3 and have set the aliases in the dockerfile. When I open the .bashrc file, they show up. As far as I can tell, it should work but the default python version is still 2.7. if I run which python, it will still point to usr/bin/python rather than python3. Same with pip. Can anyone tell me what the problem is? Here is the command I'm using to alias:
RUN \
echo 'alias python="/usr/bin/python3"' >> /root/.bashrc && \
echo 'alias pip="/usr/bin/pip3"' >> /root/.bashrc
Does this look right? I am using ubuntu 17.10
You try to create a symlink for python bin
RUN ln -s /usr/bin/python3 /usr/bin/python & \
ln -s /usr/bin/pip3 /usr/bin/pip
other option is use update-alternatives for more visit this site
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3
and another option is trying source the bashrc file after updating
RUN \
echo 'alias python="/usr/bin/python3"' >> /root/.bashrc && \
echo 'alias pip="/usr/bin/pip3"' >> /root/.bashrc && \
source /root/.bashrc
I recommend seeing all options of python images on Docker Hub
Tip: use anaconda or conda for managing your python versions (conda site)
The answer above is great, except it should be as follows:
RUN ln -s /usr/bin/python3 /usr/bin/python && \
ln -s /usr/bin/pip3 /usr/bin/pip
Perhaps they typo-ed by writing ls which just lists the contents of the directory, rather than using ln which actually creates symlinks.
On RedHat OpenShift servers it is not possible to compile node.js module canvas, because there are missing cairo libraries for the linux, and related required libraries as well.
This is how to make it compile:
export PATH=/sbin:$PATH:$OPENSHIFT_DATA_DIR/usr/local/bin
export LD_LIBRARY_PATH=$OPENSHIFT_DATA_DIR/usr/local/lib:/opt/rh/nodejs010/root/usr/lib64:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$OPENSHIFT_DATA_DIR/usr/local/lib/pkgconfig
cd $OPENSHIFT_DATA_DIR
curl -L http://sourceforge.net/projects/libpng/files/libpng16/1.6.17/libpng-1.6.17.tar.gz/download -o libpng.tar.gz
curl -L http://www.ijg.org/files/jpegsrc.v9a.tar.gz -o jpegsrc.tar.gz
curl -L http://www.cairographics.org/releases/pixman-0.32.6.tar.gz -o pixman.tar.gz
curl -L http://public.p-knowledge.co.jp/Savannah-nongnu-mirror//freetype/freetype-2.5.5.tar.gz -o freetype.tar.gz
curl -L http://www.cairographics.org/releases/cairo-1.14.2.tar.xz -o cairo.tar.xz
curl -L http://ftp.gnome.org/pub/GNOME/sources/pango/1.35/pango-1.35.3.tar.xz -o pango.tar.xz
curl -L http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.11.1.tar.gz -o fontconfig.tar.gz
curl -L http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-0.9.37.tar.bz2 -o harfbuzz.tar.bz2
curl -L http://ftp.gnome.org/pub/GNOME/sources/glib/2.34/glib-2.34.3.tar.xz -o glib.tar.xz
curl -L http://ftp.gnome.org/pub/GNOME/sources/pango/1.35/pango-1.35.3.tar.xz -o pango.tar.xz
cd $OPENSHIFT_DATA_DIR
gunzip libpng.tar.gz
tar -xvf libpng.tar
cd libpng-1.6.17/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar -zxf jpegsrc.tar.gz && cd jpeg-9a/
./configure --disable-dependency-tracking --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar -zxf pixman.tar.gz && cd pixman-0.32.6/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar -zxf freetype.tar.gz && cd freetype-2.5.5/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar --xz -xvf cairo.tar.xz && cd cairo-1.14.2/
./configure --disable-dependency-tracking --without-x --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar -xvf fontconfig.tar.gz && cd fontconfig-2.11.1/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
bunzip2 harfbuzz.tar.bz2
tar -xvf harfbuzz.tar && cd harfbuzz-0.9.37/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar --xz -xvf glib.tar.xz && cd glib-2.34.3/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar --xz -xvf pango.tar.xz && cd pango-1.35.3/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_REPO_DIR
scl enable nodejs010 v8314 'npm install canvas'
rm -rf "${OPENSHIFT_NODEJS_DIR}/tmp/saved.node_modules"
To use these libraries in the node.js server, you need to add custom LD_LIBRARY_PATH entry which points to them:
In the OpenShift git project add directory: .openshift/markers
In this directory create empty file named: use_npm
In the package.json file add this entry:
"scripts": {
"start": "export LD_LIBRARY_PATH=$OPENSHIFT_DATA_DIR/usr/local/lib:/opt/rh/nodejs010/root/usr/lib64:$LD_LIBRARY_PATH; supervisor server.js"
}
This usually works, but sometimes there are happening npm update activities which start to rebuild canvas module.
Sometimes bcrypt module does not build too.
The solution is to create one gear, where everything just works, and then to make tar.gz file with the contents of $OPENSHIFT_DATA_DIR/usr/
and to transfer this file to your server where it is accessible via http://
That same should be done for node_modules/canvas, node_modules/bcrypt and other vulnerable entries.
Then, it is possible to use OpenShift app hooks (build, etc) to download and extraxt the contents of these files in the right places.
Also, you can compile many node_modules/xxxxx on the CentOS 6.6, and then to copy these in the right places on the server, which runs RHEL 6.6
(binary compatibility stuff, just like with rpm package installation)
This way it is possible to create git repository and downloadable tar.gz files which would allow to automatically launch new RedHat OpenShift gears.
Of course, if there will be some system upgrades, tar.gz files contents must be upgraded too.
My production server (Centos 5.9) won't compile nodejs, possibly because it's gcc is only 4.1.2 (4.2 or above is recommended) so I've trying to install the binaries.
$ wget http://nodejs.org/dist/v0.10.22/node-v0.10.22-linux-x86.tar.gz
$ tar -zxvf node-v0.10.22-linux-x86.tar.gz
$ cd node-v0.10.22-linux-x86
$ sudo cp bin/* /usr/local/bin
$ sudo cp -R lib/* /usr/local/lib
$ sudo cp -R share/* /usr/local/share
And now for testing:
$ node -v # => v0.10.22
$ man node # looks fine
$ npm -v # UH OH, PROBLEM - Cannot find module 'npmlog'
Now (keeping in mind I'm a complete beginner at node) I did some searching and found there's an environment variable called NODE_PATH, so I tried:
$ export NODE_PATH=/usr/local/lib/node_modules
$ npm -v # SAME PROBLEM - Cannot find module 'npmlog'
So then I found out where npmlog lives and tried modifying NODE_PATH accordingly:
$ find /usr/local/lib -name npmlog # => /usr/local/lib/node_modules/npm/node_modules/npmlog
$ export NODE_PATH=/usr/local/lib/node_modules/npm/node_modules
$ npm -v # DIFFERENT PROBLEM - Can't find '../lib/npm.js'
At this stage, after more unhelpful googling, I decided I was in over my depth and decided to ask for help. Can anyone tell me what I'm doing wrong?
It is much faster to do clean NPM reinstall which will remove "broken" links:
wget https://npmjs.org/install.sh
chmod +x install.sh
sudo ./install.sh
Then it will ask you to remove old NPM link
Using Node Version Manager
Use a Node version manager like nvm to handle installation and version management for you. After you install nvm you can simply install any Node version, for example nvm install 8.
But if you just want to install the binary yourself, see below:
Using apt-get
In special cases where you need a system wide Node installation, you can use apt-get:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
The above snippet will install the latest Node 8.
Installing the Binary Manually
In order to install the binary manually, all you need to do is to download the binary and create a bunch of symbolic links. Execute the commands below one after the other, and it should do the job. I have also written a shell script that does it for you if that is easier (see the bottom of the answer). Hope that helps.
Make sure to use the correct download link for your OS architecture (i.e. either 32-bit or 64-bit) for wget on the second line.
ME=$(whoami) ; sudo chown -R $ME /usr/local && cd /usr/local/bin #adding yourself to the group to access /usr/local/bin
mkdir _node && cd $_ && wget https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.xz -O - | tar zxf - --strip-components=1
ln -s "/usr/local/bin/_node/bin/node" .. # Making the symbolic link to node
ln -s "/usr/local/bin/_node/lib/node_modules/npm/bin/npm-cli.js" ../npm ## making the symbolic link to npm
Here is a shell script that downloads and installs all the components. If you use this script to install Node, you can use the uninstall script to uninstall it.
Installing Node
#! /bin/bash
# run it by: bash install-node.sh
read -p " which version of Node do you need to install: for example 8.11.4 (or any other valid version): " VERSIONNAME
read -p " Are you using a 32-bit or 64-bit operating system ? Enter 64 or 32: " ARCHVALUE
if [[ $ARCHVALUE = 32 ]]
then
printf "user put in 32 \n"
ARCHVALUE=86
URL=https://nodejs.org/dist/v${VERSIONNAME}/node-v${VERSIONNAME}-linux-x${ARCHVALUE}.tar.gz
elif [[ $ARCHVALUE = 64 ]]
then
printf "user put in 64 \n"
ARCHVALUE=64
URL=https://nodejs.org/dist/v${VERSIONNAME}/node-v${VERSIONNAME}-linux-x${ARCHVALUE}.tar.gz
else
printf "invalid input expted either 32 or 64 as input, quitting ... \n"
exit
fi
# setting up the folders and the the symbolic links
printf $URL"\n"
ME=$(whoami) ; sudo chown -R $ME /usr/local && cd /usr/local/bin #adding yourself to the group to access /usr/local/bin
mkdir _node && cd $_ && wget $URL -O - | tar zxf - --strip-components=1 # downloads and unzips the content to _node
cp -r ./lib/node_modules/ /usr/local/lib/ # copy the node modules folder to the /lib/ folder
cp -r ./include/node /usr/local/include/ # copy the /include/node folder to /usr/local/include folder
mkdir /usr/local/man/man1 # create the man folder
cp ./share/man/man1/node.1 /usr/local/man/man1/ # copy the man file
cp bin/node /usr/local/bin/ # copy node to the bin folder
ln -s "/usr/local/lib/node_modules/npm/bin/npm-cli.js" ../npm ## making the symbolic link to npm
# print the version of node and npm
node -v
npm -v
Uninstalling Node
#! /bin/bash
# run it by: ./uninstall-node.sh
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/lib/node_modules/
sudo rm -rf /usr/local/include/node/
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/bin/_node/
I had a problem like that, but with iojs. However it should be the same procedure:
(Assuming that you've got a file matching node-v*-linux-x64.tar.gz in your current directory):
# In case of iojs you need to replace the occurrences of 'node' with 'iojs'
# Extract the downloaded archive with the linux-x64 version of node
tar zxf node-v*-linux-x64.tar.gz
# Move the extracted folder (./node-v*-linux-x64/) to /opt/
mv ./node-v*-linux-x64/ /opt/
To make the binary files available in your shell, create some softlinks inside the /usr/bin/ directory:
# Create a softlink to node in /usr/bin/
ln -s /opt/node-v*-linux-x64/bin/node /usr/bin/node
# Create a softlink to npm in /usr/bin/
ln -s /opt/node-v*-linux-x64/bin/npm /usr/bin/npm
# Create a softlink to iojs in /usr/bin (this step can be omitted if you're using node)
ln -s /opt/node-v*-linux-x64/bin/iojs /usr/bin/iojs
Notice: If you'd like to access the cli of some globally installed node modules (for example bower, typescript or coffee-script), you're required to create a softlink to each of those executables in the /usr/bin/ directory.
Alternatively you could just add the bin directory of your node installation directory (e.g. /opt/node-v*-linux-x64/) to the PATH environment variable: (you should use the absolute path for this!)
# create a new .sh script in /etc/profile.d which adds the directory to PATH
echo "export PATH=$PATH:/opt/node-v0.12.3-linux-x64/bin" > /etc/profile.d/node-npm.sh
This change will take effect after logging out and in again.
Both methods worked for me (I use a linux desktop version of Ubuntu 14.04/15.04 with GNOME 3).
I had the same issue reported here. Fixed it by removing /usr/local/bin/npm and replacing it with a symlink to /usr/local/lib/node_modules/npm/bin/npm-cli.js
$ ls -l /usr/local/bin/
node
npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
$ npm -v
1.3.17
wget <node archive url from nodejs.org>
cd /usr/local
sudo tar --strip-components 1 -xf <path to node archive>
You can run node and npm right away.
It used to be documented in the README inside the archive in older versions.
I had the same problem and I was able to resolve it by creating symlinks instead of copying the binaries.
$ cd /usr/local/src
$ wget http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-x64.tar.gz
$ tar -zxvf node-v0.10.24-linux-x64.tar.gz
$ cd node-v0.10.24-linux-x64
$ sudo cp -R lib/* /usr/local/lib
$ sudo cp -R share/* /usr/local/share
$ ln -s /usr/local/src/node-v0.10.24-linux-x64/bin/node /usr/local/bin/node
$ ln -s /usr/local/src/node-v0.10.24-linux-x64/bin/npm /usr/local/bin/npm
$ node -v
v0.10.24
$ npm -v
1.3.21
I tend to use nave to install the binaries. Use wget to download the nave.sh file and then us it to install node. Nave is also nice to have around in case one of your production apps requires a different version of node than what's installed globally.
$ wget https://raw.github.com/isaacs/nave/master/nave.sh
$ sudo bash nave.sh usemain 0.10.22
You can use GNU stow to make symbolic links of those binaries in /usr/local properly with one command. Stow also allows you to easily remove Node js from /usr/local at a later time and swap multiple versions of Node js.
$ # first, install stow
$ mkdir /usr/local/stow # if it doesn't exist
$ # then, place software binary package in /usr/local/stow
$ cd /usr/local/stow
$ stow <package_name> # install / add sym links
$ source $HOME/.bash_profile # reload your environment
$ # node -v and npm -v should now work
$ stow -D <package_name> # uninstall / remove sym links
These steps worked for me with node-v0.10.17-linux-x64.
In the man page of cp in Mac OS X:
Symbolic links are always followed unless the -R flag is set, in which case symbolic links are not followed, by default.
When you execute sudo cp bin/* /usr/local/bin, the symbolic link bin/npm is followed.
Actually, bin/npm is linked to ../lib/node_modules/npm/bin/npm-cli.js, so cp will copy npm-cli.js to /usr/local/bin. That's why you get an error.
I had the same problem.
The problem is the npm excutable in /usr/local/bin.
The way I solved it was:
sudo rm /usr/local/bin/npm
sudo ln -s "/usr/local/lib/node_modules/npm/bin/npm-cli.js" /usr/local/bin/npm
In Ubuntu there is a .bashrc file which sets path to binaries.
By default, there is path set for bin in home directory. Perhaps you can create bin directory in your home directory and move the binaries there. Reboot your system and try executing the command node
I faced the same problem. So, I symlinked node and npm from ./bin/ to /usr/local/bin
If someone is interested in using Docker, in the Dockerfile,
ENV NODE_VERSION 8.10.0
RUN wget https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz
RUN tar -xJvf node-v$NODE_VERSION-linux-x64.tar.xz -C /usr/local/
ENV NODEJS_HOME /usr/local/node-v$NODE_VERSION-linux-x64
ENV PATH $NODEJS_HOME/bin:$PATH
RUN node --version
RUN npm --version