Installing java using chef - java

I know how to install java on linux machine using terminal. But i want to automate the installation using Chef Framework. I have two machines M1 and M2. I am on machine M1 and want to install java on machine M2. This is what i do in using terminal....
first i SSH into machine M2, after i do the following things... (in here i download the java files from third party storage.)
Step1:-
cd setup
step2:-
wget http://downloads.company.com/downloads/DevTools/jdk/6.0/jdk-6u31-linux-i586.bin
Step3:-
chmod +x jdk-6u31-linux-i586.bin
Step4:-
yes | ./jdk-6u31-linux-i586.bin
Step5:-
cd /usr/bin
Step6:-
mv java javaorg
Step7:-
cd /usr
Step8:-
ln -s /home/harish/setup/jdk1.6.0_31 java
Step9:-
echo 'export PATH=$PATH:/usr/java/bin' > /etc/profile.d/alljava.sh;echo 'export JAVA_BINDIR=/usr/java/bin' >> /etc/profile.d/alljava.sh;echo 'export JAVA_ROOT=/usr/java' >> /etc/profile.d/alljava.sh;echo 'export JAVA_HOME=/usr/java' >> /etc/profile.d/alljava.sh;echo 'export JRE_HOME=/usr/java/jre' >> /etc/profile.d/alljava.sh
Step10:-
source /etc/profile.d/alljava.sh
Step11:-
echo $JAVA_HOME
Step12:-
java -version
I have following questions:
what is the category of the problem (chef-solo or shef-server)
do i need to have machine M2 installed Chef.
i have downloaded the cookbook for JAVA from GitHub but i don't know what to do with that.
i have written some code for installing java on SAME machine.. but it also not working..
CODE:
#cookbook/java/recipe/default.rb
*####This will install JAVA on machine M1######*
execute "copy" do
cwd "/home/user/setup"
command "wget http://downloads.company.com/downloads/DevTools/jdk/6.0/jdk-6u31-linux-i586.bin"
end
execute "change_mode" do
command "chmod +x jdk-6u31-linux-i586.bin"
end
execute "dont_know" do
command "yes | ./jdk-6u31-linux-i586.bin"
end
execute "make link" do
command "ln -s /home/harish/setup/jdk1.6.0_31 java"
end
java_home = "export JAVA_HOME=/usr/java/jdk1.6.0_31"
path = "export PATH=$PATH:JAVA_HOME/bin"
file "/etc/profile" do
content "#{java_home}\n#{path}"
owner "root"
end
but this code is giving some big messages..(errors).
can anybody help through this and also how to use the downloaded cookbooks for JAVA.. thanks. :)

This is a long out-of-date question, but I'll include an answer in case someone stumbles in on this one.
Opscode has a Java cookbook that they maintain that can install either OpenJDK or Oracle JDK. It's available at the opscode community site here.
You can use it by adding a dependency to your cookbook's metadata.rb:
depends "java", "~> 1.10.2"
and including the recipe in your cookbook's default.rb:
include_recipe "java"

Related

Install Java 16 on Raspberry Pi 4

I have tried multiple releases from here using :
sudo -i
cd /usr/lib/jvm
wget [release link here]
tar xzf [file name here]
export PATH=$PWD/[dir here]/bin:$PATH
java -version
But after java -version I always get:
/usr/lib/jvm/[dir here]/bin/java: cannot execute binary file: Exec format error
Which means I have chosen the wrong release/architecture. Is there a release that works with Raspberry Pi's or is there another way to install Java 16?
Answering my own question.
cd [minecraft directory here]
wget https://github.com/AdoptOpenJDK/openjdk16-binaries/releases/download/jdk16u-2021-05-08-12-45/OpenJDK16U-jdk_arm_linux_hotspot_2021-05-08-12-45.tar.gz
tar xzf OpenJDK16U-jdk_arm_linux_hotspot_2021-05-08-12-45.tar.gz
export PATH=$PWD/jdk-16.0.1+4/bin:$PATH
java -version
You might have to do
export PATH=$PWD/jdk-16.0.1+4/bin:$PATH
after a reboot

Cordova can't find my Java installation, but JAVA_HOME looks valid. What's going on?

Windows 7 64-bit, with 64-bit JDK. Cordova plugman 1.4.2-dev. Using cygwin bash as a shell, but I don't see why that would affect anything.
$ echo $JAVA_HOME
"c:\Program Files\Java\jdk1.8.0_25"
$ echo $ANDROID_HOME
C:\Users\admin\AppData\Local\Android\Sdk
$ ls "c:\Program Files\Java\jdk1.8.0_25"
bin include lib release
COPYRIGHT javafx-src.zip LICENSE THIRDPARTYLICENSEREADME.txt
db jre README.html THIRDPARTYLICENSEREADME-JAVAFX.txt
$ ./main.js install --platform android --project ../myproject/ --plugin phonegap-facebook-plugin-gtg --variable APP_ID="1155264567919069" --variable APP_NAME="Voice Test"
Fetching plugin "phonegap-facebook-plugin-gtg" via npm
Installing "phonegap-facebook-plugin" for android
Failed to install 'phonegap-facebook-plugin':CordovaError: Failed to run "javac -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: "c:\Program Files\Java\jdk1.8.0_25"
I've also tried using JAVA_HOME without the quotes. What's going on?
#cubrr gave the correct answer in the comments. The error message being produced by Cordova is extremely misleading: the problem isn't that JAVA_HOME was incorrect, but that javac wasn't on my path. This was made all the more confusing by the fact that java was on my path, so when I checked it gave correct results. This is because the Oracle installer adds a directory to your path (c:\ProgramData\Oracle\Java\javapath) that contains links to java.exe and related programs but not the relevant JDK programs.
1) set > system variables > path to
`;C:\Program Files\Java\jdk1.8.0_xxx\bin;`
2) create new JAVA_HOME path with the value
C:\Program Files\Java\jdk1.8.0_xxx
now check javac version by issuing command at CMD
javac -version
*** don't touch the oracle - "C:\ProgramData\Oracle\Java\javapath;" path
If you are running windows 10, you need to restart your computer after changing the path and other variables. Possibly also on earlier windows versions.

Installing JDK on Linux

I’m trying to install JDK on Centos, but I’m getting an error:
[root#www opt]# rpm -ivh /opt/jdk-7u51-linux-x64.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
error: unpacking of archive failed on file /usr/java/jdk1.7.0_51/db/lib/derbyLocale_zh_CN.jar;533ab42a: cpio: read
Where can be problem?
Thanks
Can you please check the md5sum of the downloaded file against these values here: http://www.oracle.com/technetwork/java/javase/downloads/java-se-binaries-checksum-1956892.html ?
If the md5sum does not check, it must be a broken download.
A short answer: try downloading and installing again.
A longer answer:
Even though you are getting this, the jdk is getting installed. Sort of. This seems to be an error in the packaging but it is not fatal. Here is the output from my machine. In the example I cat'd the release file so you can see what CentOS I'm using and did an md5sum on the rpm I'm using. You'll notice that it doesn't match the md5sum from the Oracle site link (provided above by Kristof).
Next, I did an ls on the target directory for the jdk /usr/java/ so you can see that it is empty. Then ran the rpm install and did another ls to show that some files are there.
Of course, this defeats the purpose of using rpm, because the install information is not going to go into the rpm database. If I query the database it doesn't come up and it's missing the links that usually get installed pointing to 'latest' and 'default'
So I took a guess that maybe there is a mirror that might have a bad rpm and went to the Oracle site and downloaded the file again. I gave it a different name so that I can compare the two files. This time it was successful.
In the screen shot below you can see the two files. The newest download being the one I called jdk-7u51-linux-x86_64.rpm. You can see the md5sum shows the files are different, but on the new file, the md5 matches the Oracle site. I removed the directory that was created by the failed install and then ran the rpm -ivh command and it completed successfully. The ls on the /usr/java directory shows all the correct stuff and querying the rpm database shows it was installed. Hope this helps!
You can do it with simple script which you can find here
It's for Centos rpm, but you can edit script and change rpm to tar.gz for example
Also you can change version or env in variables bellow
BASE_URL="technetwork/java/javase/downloads"
BASE_URL_OUTPUT="$(curl -s -L0 http://www.oracle.com/${BASE_URL}/)"
JAVA_ENVIRONMENT="JDK"
JAVA_BASE_VERSION=8
DOWNLOAD_SITE="$(echo $BASE_URL_OUTPUT | grep -m 1 -io "${JAVA_ENVIRONMENT}${JAVA_BASE_VERSION}-downloads-[0-9]*.html" -- | tail -1)"
echo "DOWNLOAD_SITE="$DOWNLOAD_SITE
DOWNLOAD_LINK_OUTPUT="$(curl -s -L -j -H "Cookie: oraclelicense=accept-securebackup-cookie" http://www.oracle.com/${BASE_URL}/${DOWNLOAD_SITE} | grep -io "filepath.*${JAVA_ENVIRONMENT}-[${JAVA_BASE_VERSION}].*linux[-_]x64[._].*\(rpm\)" -- | cut -d '"' -f 3 | tail -1)"
echo "DOWNLOAD_LINK_OUTPUT="$DOWNLOAD_LINK_OUTPUT
curl -L -o java_rpm_packet.rpm -b "oraclelicense=a" $DOWNLOAD_LINK_OUTPUT
and install with
yum localinstall -y java_rpm_packet.rpm

Add the play script to your PATH in Mac

I'm not good with the terminal, so I have no idea what this means....
you should add the framework installation directory to your system PATH. On UNIX systems, this means doing something like:
export PATH=$PATH:/path/to/play20
On Windows you’ll need to set it in the global environment variables. This means update the PATH in the environment variables and don’t use a path with spaces.
If you're on UNIX, make sure that the play script is executable (otherwise do a chmod a+x play).
Can someone guide me through these steps. I have the Play 2.0 Folder placed in my /Documents.
I would suggest installing Play with Brew if using OS X on Mac.
First install Brew
ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
Then install Play
brew install play
Open .bash_profile
vi ~/.bash_profile
Ensure that /usr/local/bin is in your path by updating or adding the PATH line to something like this :
PATH=/usr/local/bin:$PATH
Open a new terminal window, and Play should be on your path.
You may also want to install (via brew) Scala, SBT etc.
This is what I did:
Download the play framework, extracted it to my desktop, open up iterm and vi ~/.bash_profile
add path: export PATH=$PATH:/Users/*your-username*/Desktop/play-2.2.0 save the file (that's press esc and type :wq [save and quit]) reload your bash_profile, just type source ~/.bash_profile cd to your directory and type play and your done.
Hope that's helpful.
In export PATH=$PATH:/path/to/play20, /path/to/play20 is a placeholder for your real path, which should be /Users/ronyjohn007/Documents/play20 [drag the folder from Finder into Terminal window for the actual name] - so type:
export PATH=$PATH:/Users/ronyjohn007/Documents/play20
This tells your shell to look into such folder for executables. Then:
chmod +x /Users/ronyjohn007/Documents/play20/play
This gives play file execution permission. Now close and reopen Terminal, and type play followed by enter.
You can also use symlink(s) in /usr/bin to point exact file, this is usefull, when you're using more than one version of play on the system
BTW (I can see that you performed reverse operation in your previous question :) -removed the previous: /usr/bin/play command )
(paste each line separately and confirm):
sudo -i
cd /usr/bin
chmod +x /Users/ronyjohn007/Documents/play-2.0.3/play
ln -ls /Users/ronyjohn007/Documents/play-2.0.3/play play
exit
Other sample - git master in this case
# this creates new folder in your docs,
# and clones current master version of Play from GitHub to
# /Users/ronyjohn007/Documents/play-from-github/Play20 folder
cd ~/Documents
mkdir play-from-github
cd play-from-github/
git clone https://github.com/playframework/Play20.git
# this sets alternative command as in sample 1
sudo -i
cd /usr/bin
chmod +x /Users/ronyjohn007/Documents/play-from-github/Play20/play
ln -ls /Users/ronyjohn007/Documents/play-from-github/Play20/play play-master
exit
Finally now you can check which command points to which version:
ls -la /user/bin | grep play
should give something like:
... play -> /Users/ronyjohn007/Documents/play-2.0.3/play
... play-master -> /Users/ronyjohn007/Documents/play-from-github/Play20/play
after terminal reopen they both should be available as common commands.
Note: of course you can't use play command with applications created with play-master new ... and vice-versa!
You can edit your ~/.profile file and add:
export PLAY_HOME=your-play-directory
export PATH=$PATH:$PLAY_HOME

JAVA_HOME environment variable not set Validator.nu HTML Parser

I am trying to install a local version of the Validator.nu server and it keeps failing on trying to build the HTML Parser.
It says it can't find the JAVA_HOME variable which I have set in my .bashrc file and shows correctly when I type "echo $JAVA_HOME" at the prompt
Ideas appreciated thanks
Error output
"hg" pull --update -R build https://bitbucket.org/validator/build/
Not trusting file build/.hg/hgrc from untrusted user dave, group dave
Not trusting file /home/dave/src/checker/build/.hg/hgrc from untrusted user dave, group dave
warning: bitbucket.org certificate with fingerprint 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe not verified (check hostfingerprints or web.cacerts config setting)
pulling from https://bitbucket.org/validator/build/
warning: bitbucket.org certificate with fingerprint 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe not verified (check hostfingerprints or web.cacerts config setting)
searching for changes
no changes found
Error: The JAVA_HOME environment variable is not set.
Set the JAVA_HOME environment variable to the pathname of the directory where your JDK is installed.
Instead of:
$ sudo python build/build.py all
try:
$ sudo -E python build/build.py all
The sudo command for security reasons resets the environment (so your JAVA_HOME for the python process is wiped out even when it's exported). The "sudo -E" will preserve the environment.
I assume (from tag) you use ubuntu.
list versions of installed javas in your system:
dave#ubuntu:~$ update-java-alternatives --list
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
Note, that if you set JAVA_HOME in ~/.bashrc it will be set only in your terminal sessions.
Unless you export it, it will be set only for your current shell process (not subprocesses like mercurial).
add line to your .bashrc:
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk"
open a new terminal and test it:
$JAVA_HOME/bin/java -version && echo java seen by bash
bash -c '$JAVA_HOME/bin/java -version && echo java seen by bash subprocesses'
If you want to set environment for all processes (not only started by hand from terminal), you can:
dave#ubuntu:~$ sudo $EDITOR /etc/environment
After tackling this for the last 4 days I have managed to get the validator.nu server running on my local Ubuntu VM and so I thought I would update this thread in case anyone else runs in to the same issues.
I am still not 100% sure where the original issue with the JAVA_HOME variable was coming from but I suspect (although I am not an expert at this) that it had something to do with the way I was using sudo to run the python build.
I was initially following the instructions on http://about.validator.nu/#src but using
$ sudo python build/build.py all
This was because part of the build needed the correct permissions to work.
This is my step-by-step process which starts from a clean install of Ubuntu 11.
installed ubuntu 11
opened the terminal
sudo /bin/bash <----------- I THINK THIS IS THE CRUCIAL LINE
apt-get install mercurial
apt-get install subversion
apt-get install openjdk-6-jre
apt-get install openjdk-6-jdk
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
follow rest of http://about.validator.nu/#src instructions
I'm going to need to do it again when I set this up for the internal network for our build scripts so i'll edit this if I've missed out on anything.
Hope this saves another person's headache and lost days!

Categories

Resources