Using UBUNTU, I installed java 8 with the following command
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
$ sudo apt-get install oracle-java8-set-default
and I'm trying to set the java environment path as follow
$ cat >> /etc/environment <<EOL
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
EOL
but I get this error message:
bash: /etc/environment: permission denied
Assuming that you have already the following:
$sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
$ sudo apt-get install oracle-java8-set-default*
Open /etc/environment file with the following command.
sudo nano /etc/environment
N/B: You can replace nano with any other editor you like e.g atom
At the end of file, add
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
The command above alone worked for me but you can also add the command below if you want.
JRE_HOME="/usr/lib/jvm/java-8-oracle/jre"
Remember the path used here was my java installation directory, if yours is the same then you don't need to change anything, otherwise use your path.
Check whether your changes persisted
$ source /etc/environment
$ echo $JAVA_HOME
https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04
Try this script, save it in a file.sh
#!/bin/bash
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install openjdk-8-jre -y
sudo cat >> /etc/environment <<EOL
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
EOL
Try with sudo
$ sudo cat >> /etc/environment <<EOL
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
EOL
Use the following lines to set the path variables in the /etc/environment
echo export JAVA_HOME=/path/to/java | sudo tee -a /etc/environment
echo export JRE_HOME=/path/to/jre | sudo tee -a /etc/environment
It should work.
Note:
You should reboot the system for changes to take effect.
And don't forget to come here after reboot and vote +1 :)-|-<
Following is the method that worked for me -
Use bashrc to create environment variable :
JAVA_HOME=/path/to/java
JRE_HOME=/path/to/jre
sudo vim ~/.bashrc
Enter Password
Press I(Key) to go in the insert mode
Write export JAVA_HOME='/path/to/java' at the end of file
Write export JRE_HOME='/path/to/jre' at the end of file
Save and Exit (:wq)
Related
As the titles says, I am triying to install maven 3.8 and jdk17 in a virtual machine using vagrant. This is what I have:
Vagrantfile:
...
config.vm.provision "shell", path: "vagrantScripts/jdk17.sh"
...
jdk17.sh:
#jdk17 installation
curl -O https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
sudo tar -xvf jdk-17_linux-x64_bin.tar.gz
sudo mv jdk-17.0.2 /opt/jdk17
export JAVA_HOME=/opt/jdk17
export PATH=$PATH:$JAVA_HOME/bin
#maven 3.8.5 installation
curl -O https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
sudo tar -xvf apache-maven-3.8.5-bin.tar.gz
sudo mv apache-maven-3.8.5 /opt/maven
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
If I do line by line coding in the command shell of the VM, everything works fine, but when I try to automate the installation using provision, it just doesn't work.
Any help?
Thanks
Install JAVA
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install -y openjdk-8-jdk
Install Maven ( on Jenkins machine )
cd /tmp
sudo wget https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
cd /tmp
sudo tar -xzf apache-maven-3.8.5-bin.tar.gz -C /opt/
mv /opt/apache-maven-3.8.5 /opt/maven
When I am Running My Vagrantfile with its shell, I'm struggle with Java 8 install with this exact same error :
StackOverflow - jdk-8-is-not-installed-error-404-not-found
In order to fix that error, I added those lines :
sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' /var/lib/dpkg/info/oracle-java8-installer.*
I have in my Shell this block for java section:
# /*======================
# = JAVA =
# ======================*/
# https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-debian-8
sudo apt-get install -y software-properties-common
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
sudo apt-get update
# Silent !! Sshh !
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
# see https://stackoverflow.com/questions/46815897/jdk-8-is-not-installed-error-404-not-found
# Still not work
sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo apt-get install -y oracle-java8-installer
sudo apt-get install -y oracle-java8-set-default
The weird thing is : Those lines taken one by one via SSH when the box is started and you can install Java, it Works. But it's not working when I provision for the first time my vagrant box.
Is the problem comes from sed or another command ? I suppose it's the sed's command but don't know how to fix it, because it's working if I paste them via SSH.
I want to make this work without any manual interventions.
You can test my VM using this github repo (V2) :
VagrantFile + shells
How can I make this work using vagrant up ?
EDIT :
I've tested it on Vagrant 2.0 and virtualBox 5.6
Also tested with vagrant 1.7 and virtualBox 5.1
I'm putting this in just in case anyone is fine with Debians basic version, but has missed it. I think it should already be installed on anything but the most bare-bones systems.
To get openJDK working, which is the version offered in Debians standard repos, you would just need to use
apt-get install -y openjdk-8-jdk
There are other debug and docs packages as well.
Debian also provide a package in the contrib repos called java-package which converts the source tarball from the Oracle site (you have to get it yourself to OK the terms and conditions), and creates a deb from it. Unfortunately there doesn't seem to be a way to directly presume yes to the questions asked, so it would need an expect script or something.
config.vm.provision "shell", inline: <<-SHELL
# add contrib repos into source files.
mv /etc/apt/sources.list /etc/apt/sources.bk
sed -r ‘s/stretch([^ ]*) main$/& contrib/‘ /etc/apt/sources.bk | sudo tee /etc/apt/sources.list
# vi -c ':%s/stretch\([^ ]*\) main$/& contrib/g' /etc/apt/sources.list -c 'wq'
apt-get update
apt-get install -y java-package java-common expect
# some `expect` needed magic here
sudo -u vagrant fakeroot make-jpkg /vagrant/jdk-8*
dpkg -i oracle-java8*
SHELL
In terms of the interactions I get using make-jpkg, this script works (from the command line)
expect -c '
set timeout -1
spawn fakeroot make-jpkg /vagrant/jdk-8u162-linux-x64.tar.gz
expect "Is this correct \\\[Y/n\\\]: $" { send "Y\r" }
expect "Press \\\[Return\\\] to continue: " { send "\r" }
expect "*Press \\\[Return\\\] to continue or Ctrl-C to abort." { send "\r" }
expect eof { exit 0 }
'
but could probably be done other ways.
So almost an answer, but may get you a bit closer.
Sorry for my late answer. Another option is to mount a drive and install the oracle rpm package silently.
Create directory and put there your Vagrantfile. This the root of your project. (./)
Vagrantfile
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "bento/centos-7.4"
config.vm.boot_timeout = 240
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# View the documentation for the provider you are using for more
# information on available options.
config.vm.provider "virtualbox" do |vb|
# Enable the Host I/O cache for more performance
vb.customize [
"storagectl", :id,
"--name", "SATA Controller",
"--hostiocache", "on"
]
vb.auto_nat_dns_proxy = false
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"
vb.customize ["modifyvm", :id, "--memory", 4096]
vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
vb.cpus = 4
end
# Synced folders are configured within your Vagrantfile using the config.vm.synced_folder method.
# Vagrant shares by default the root directory of (./) with guest on /vagrant
config.vm.synced_folder ".", "/vagrant", disabled: true
# Synced folder is set as read-only for guest machine. You can configure the files on the host machine.
# For more mount options check: http://manpages.ubuntu.com/manpages/precise/man8/mount.vboxsf.8.html
config.vm.synced_folder "./installfiles", "/installfiles",
owner: "vagrant", group: "vagrant", mount_options: ["ro"]
# Bootstrap shell scripts.
config.vm.provision "shell", path: "./bootstrap/setup.sh"
config.vm.post_up_message = "Finsihed provisioning!\n" \
"Type \"vagrant ssh\" to get started"
end
Create another directory named bootstrap from the root of your project. Create an empty file called setup.sh, put the content below in the setup.sh file. The file path will be ./bootstrap/setup.sh
setup.sh
#!/usr/bin/env bash
echo "installing Java 8 64 bit"
sudo rpm -i /installfiles/java8/jdk-8u144-linux-x64.rpm
unzip /installfiles/java8/jce_policy-8.zip -d /tmp
sudo cp -f /tmp/UnlimitedJCEPolicyJDK8/* $JAVA_HOME/lib/security/
Go to the oracle website download the correct 32 or 64 bit rpm linux package. Versions available on the oracle website might change. For this example i downloaded the jdk-8u144-linux-x64.rpm package. I also downloaded the unlimited encryption strength policy from the oracle website, name of the file is: jce_policy-8.zip.
Create two directories from the root of your project named installfiles/java8. Place the downloaded files in there. The files path will be: ./installfiles/java8/jdk-8u144-linux-x64.rpm and ./installfiles/java8/jce_policy-8.zip
Run the command vagrant up. On your host machine the directory ./installfiles will be synchronised with your virtualbox guest machine on the path /installfiles. During the provisioning state of vagrant java-8 will be installed automatically. Keep in mind that the rpm package manager comes out of the box with Red Hat distros. But it is also possible to install rpm packages on debian distros.
The following snippet fixes the silent install of java from webupd8team repo for Debian distribution
sudo apt-get -y install software-properties-common
sudo add-apt-repository -y ppa:webupd8team/java
sudo bash -c "echo deb http://http.debian.net/debian jessie-backports main >> /etc/apt/sources.list"
sudo bash -c "echo deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main >> /etc/apt/sources.list.d/webupd8team-java.list"
sudo bash -c "echo deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main >> /etc/apt/sources.list.d/webupd8team-java.list"
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update
sudo apt-get -y upgrade
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selectionssudo
sudo apt-get -y install oracle-java8-installer oracle-java8-set-default
As of today, it installs the following
vagrant#debian-8:~$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
I'm using Ubuntu 16.04 64-bit. I installed Oracle JDK jdk1.8.0_144 in /usr/local/java and set the symlinks as below.
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_144/jre/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_144/bin/javac" 1
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_144/jre/bin/javaws" 1
$ sudo update-alternatives --set java /usr/local/java/jdk1.8.0_144/jre/bin/java
$ sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_144/bin/javac
$ sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_144/jre/bin/javaws
After that, I followed the installation guide in the WSO2 documentation and set JAVA_HOME as below.
nano /.bashrc
added the variable:
export JAVA_HOME=/usr/local/java/jdk1.8.0_144
export PATH=${JAVA_HOME}/bin:${PATH}
I close the old terminals and open a new one and run:
echo $JAVA_HOME
and I get
/usr/local/java/jdk1.8.0_144
However, when I run sh wso2server.sh I get the error:
JAVA_HOME is not defined correctly.
CARBON cannot execute java
error.
You should try to add the following into your .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/jre/bin:$PATH
There is similar issue: Ubuntu: JAVA_HOME is not defined correctly
There are many other causes of this issue:
1) You are running the server as the super user (sudo) which is not required. However I think you dont have the JAVA_HOME set in super user environment.
2) You can try: sudo JAVA_HOME=/usr/lib/jvm/java-7-oracle ./wso2server.sh
3) You should probably be setting JAVA_HOME to /usr/lib/jvm/jdk1.7.0/jre rather than /usr/lib/jvm/jdk1.7.0.
4) Your version of Identity Server does not support java 8.
replace your java home path in wso2server.sh line no 52
#JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
I tried to install oracle-java7 on my Linux Mint with the codes above. After executing those codes, I tried to check if its working by typing "java -version" but suddenly an error occured.
bash: /usr/bin/java: cannot execute binary file: Exec format error
You can install a package to set (and keep) oracle-java7 as the default; or you can manually set the java alternative with update-java-alternatives. Something like,
Option 1. sudo apt-get install oracle-java7-set-default
Option 2. sudo update-java-alternatives -s java-7-oracle
I'm using Vagrant to simulate a network for a distributed system project. I'm using this file provision.sh in order to provision each machine in the cluster:
sudo apt-get update
sudo apt-get install -y openjdk-7-jdk
sudo apt-get purge -y openjdk-6-jre
sudo apt-get purge -y openjdk-6-jre-lib
sudo apt-get install -y maven
echo "export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-i386" >> /home/vagrant/.profile
echo "export PATH=$JAVA_HOME/bin:$PATH" >> /home/vagrant/.profile
mvn clean -f /vagrant/RaftFS/pom.xml
mvn package -f /vagrant/RaftFS/pom.xml
sudo mv /vagrant/RaftFS/target/RaftFS-1.0-SNAPSHOT-jar-with-dependencies.jar /vagrant/
sudo cp /vagrant/RaftFS/servers.yaml /vagrant/
But when I access to the VM and I run java -version it says that the version 6 is still installed! How is that possible? As suggested by #ydaetskcoR if I execute env | grep JAVA_HOME it returns JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-i386 ...so I don't get why it says that the java version is 6
Just for completeness, this is the Vagrant file:
# -*- mode: ruby -*-
# # vi: set ft=ruby :
# Specify minimum Vagrant version and Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
# Require YAML module
require 'yaml'
# Read YAML file with box details
servers = YAML.load_file('RaftFS/servers.yaml')
# Create boxes
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Iterate through entries in YAML file
servers.each do |key,value|
config.vm.define key do |srv|
srv.vm.box = value['box']
srv.vm.network "private_network", ip: value['ip']
srv.vm.hostname=key
srv.vm.synced_folder ".", "/vagrant" , disabled:true
srv.vm.synced_folder "ServersFS/"+key+"/", "/vagrant/ServersFS" , create: true
srv.vm.synced_folder "./RaftFS", "/vagrant/RaftFS"
srv.vm.provision :shell, path: "provision.sh"
srv.vm.provider :virtualbox do |vb|
vb.name = key
vb.memory = value['ram']
end
end
end
end
and this is servers.yaml file:
hal9000:
box: hashicorp/precise32
ram: 512
ip: 172.17.8.101
ftpPort: 8080
skynet:
box: hashicorp/precise32
ram: 512
ip: 172.17.8.102
ftpPort: 8081
jarvis:
box: hashicorp/precise32
ram: 512
ip: 172.17.8.103
ftpPort: 8083
After installing new Java version, you must to inform your system where your Oracle Java JDK/JRE is located and with version must be used as default. This will tell the system that the new Oracle Java version is available for use.
For this you must use "update-alternatives", something like this:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_20/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_20/bin/javac" 1
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_20/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_20/bin/javac
Change paths to your openjdk-7-jdk files
I found out by myself the answer to my problem: I had simply to update the system's alternatives with these two commands:
sudo apt-get install icedtea-7-plugin
sudo update-java-alternatives -s java-1.7.0-openjdk-i386
The first one is necessary since this error would be thrown otherwise:
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so
Now if I run java -version the correct version (7) is returned.