.Sh script to install java at a specific location - shell

I am using following command to install java 8 in my ubuntu 32 bit matchine.I am using .sh file to run these commands-
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-set-default
read -t 10
It's working fine but I am facing two problems
It set default location in environment variable of java(I want to install in my specific direcory like home/abc/ something and set enviornment variable according to that)
I want to pause script for 10 seconds at the end to check console.
I just want to check either my enviornment variable is set or not I am using this comamnd in my .sh file
export PATH=$PATH:$(pwd)/Linux_32/Software/jdk1.8.0_20/bin
and when I open terminal and check
java -version
It does not show me anything that is why I what to check is there anything problem with java installation. but each time .sh terminal get closed

It appears you are trying to run java -version after the script but the modified PATH environment variable does not persist beyond the script. They're running in different shells. To validate, run printenv PATH and you'll notice the jdk path is not appended.
You could try running java -version within the script or add the jdk to your PATH after the script runs, e.g. in your .profile or .bashrc.

Related

Run python script in virtualenv from bash script

I am trying to write a script, which starts pgadmin4. The program starts if I run the script python3 web/pgAdmin4.py from its own folder, but that isn't as fast as running a command from $PATH...
I managed to write a shell script based on other answers from different posts, but sadly the virtual environment still doesn't work (I assume).
The shell script:
#!/bin/bash
source ~/pgadmin4/venv/bin/activate
python3 ~/pgadmin4/web/pgAdmin4.py
The output:
If you have followed these installation steps no need to activate the virtual environment. You can call the executable file pgadmin4 under bin directory that will be executed with the pgadmin4 virtual environment:
#!/bin/bash
~/pgadmin4/venv/bin/pgadmin4
The error message you provided indicates that you lack the "flask" module. Please install it through "pip install flask" or "python3 - m pip install flask".
python3 -m pip install flask

I get "laravel: command not found" on Ubuntu 20.04

I did a fresh install of Ubuntu 20.04 LTS (Focal Fossa), installed Apache, PHP, MySQL and PHP Composer seemingly without issue. However, I still cannot get laravel -V to give me a version number.
I have looked at a multitude of YouTube videos and tried my interpretation of the recommendations found here on Stack Overflow. How can I fix it?
Here's the output on my shell $PATH.
You must add PHP Composer binaries folder to your $PATH if you'd like to call the binaries globally.
A) Make sure you have the latest Laravel installer:
composer global require laravel/installer
B) Add composer bin folder to your $PATH:
Edit your .bashrc file: gedit $HOME/.bashrc
Add the following line: export PATH="$PATH:$HOME/.config/composer/vendor/bin"
C) Use the source command to force Ubuntu to reload your .bashrc file:
source $HOME/.bashrc
D) Try to output Laravel installer's version:
laravel -V
Additional explanations as requested:
To execute a command from the Linux terminal, you need to tell Linux where the program is located.
For example, you could have launched Laravel installer using the full path: $HOME/.config/composer/vendor/bin/laravel -V
But instead, you wanted to be able to call the laravel -V command directly because you don't want to type the full path every time.
Since you are on Ubuntu, the default shell program is Bash. You need to tell Bash where to look when you type a command. In this case, you want Bash to look in the $HOME/.config/composer/vendor/bin/ folder.
The configuration file for Bash is a hidden file called .bashrc located in the user home folder. Bash stores the list of special folders in a variable called $PATH. To add a new folder, we simply added it to the $PATH variable.
If you type echo $PATH in your terminal, Bash will output the content of the $PATH variable and you will see a list of folders.
Now you may ask: "Why did I have to do this? I usually don't have to mess with my Bash configuration". Yes, this is because you usually install Ubuntu packages and they are configured to work out of the box. In this case, you installed a composer package in your home directory and it's therefore up to you to configure it the way you want.
You may need to do source $HOME/.bashrc every time you open u a new terminal windows and then do laravel -v

Cannot Install Delve Go Debugger on Mac

I am trying to follow along with the following YouTube video on getting started with Go Debugging.
It recommends following the Delve installation instructions on the official Delve github repo. For Mac users, they are as follows:
Making sure the toolchain is in place
xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Using "go get" to install Delve
go get -u github.com/go-delve/delve/cmd/dlv
Making sure developer mode is enabled in Xcode
sudo /usr/sbin/DevToolsSecurity -enable
Developer mode is already enabled.
To check that the installation has been completed correctly, I tried running the following in my Go project directlry:
dlv debug
zsh: command not found: dlv
The author of the video tutorial recommends updating GOPATH and PATH variables in the ~/.bash_profile file in the case that the command is not recognized. I did so so by adding:
export GOPATH=/Users/<user_name>/go/src/
export PATH=$PATH:/Users/<user_name/go/src/my_project
However, even after doing so, I get the same result when trying to run the debugger:
dlv debug
zsh: command not found: dlv
Even if I change the shell for the default zsh to bash, using exec bash, I get the same result.
In order to run an executable, it needs to be available in your PATH.
1. Configure your path.
Make sure that your GOPATH and $GOPATH/bin directories are set correctly in your shell environment. You can do this by adding the following lines to your shell configuration.
~/.zshrc if you're using zsh.
~/.bash_profile if you're using bash.
export GOPATH="$HOME/go"
export PATH="$GOPATH/bin:$PATH"
2. Re-load your shell configuration.
Make sure to either restart your shell or run source on your shell configuration file after the changes:
source ~/.zshrc if you're using zsh.
source ~/.bash_profile if you're using bash.
3. Install the dlv package.
go install github.com/go-delve/delve/cmd/dlv
This is assuming that you're using /Users/<username>/go as your GOPATH.
You should now be able to run dlv from your terminal session.
Good luck!
Set the environment variable GOBIN to be where you want the dlv binary to be installed.
For example:
GOBIN=~/bin go install github.com/go-delve/delve/cmd/dlv
This will install dlv in ~/bin
Clarification
When you run go install, the installation path can be specified by setting the GOBIN environment variable.
There are two ways to set the environment variable:
1) Run export GOBIN=<SOMETHING> before you run go install ..
$ export GOBIN="$HOME/bin"
$ go install github.com/go-delve/delve/cmd/dlv
The export command will alter the environment in the current terminal session. Any later command you execute will see the value you set for GOBIN
When you go with this approach, you usually want to have this environment variable active not only in this session, but all future sessions as well. So it's better to add the line to your bash profile.
2) Set the environment variable only for the command.
$ A=10 some-command
In this case, some-command will see the value of the environment variable A set to '10'. If you run a later command, it will not see this value.
This approach is useful when you are just trying things out, or if you only want to set certain environment variables in certain situations.
The command line I provided as the answer follows this second approach.
It sets the GOBIN variable to the ~/bin directory, and then invokes go install in the same line. This way, this invocation of go install will install dlv in ~/bin
This of course assumes you have a bin directory in your home directory.
If you don't have such directory, then this will not work.
The idea is not to copy paste the line as is. The idea is to change ~/bin to be the directory where you would like the dlv binary to be installed.

Sencha CMD Linux command not found

I'm trying to install Sencha-Cmd-6.0.2.14 in xUbuntu.
I downloaded SenchaCmd-6.0.2-linux-amd64.sh.zip and unzipped it to my desktop.
I installed Java by executing sudo apt-get install default-jdk -y.
Then I executed ./SenchaCmd-6.0.2.14-linux-amd64.sh. The installation window appeared and I successfully went through the process.
Upon completion, I typed in sencha at the command prompt but I got a command not found error.
Sencha is probably not in your $PATH, I'm not sure where it installs but probably somewhere in your home directory. Make sure the Sencha install directory is not in your $PATH by issueing the following command in your terminal
echo $PATH
Assuming you use bash and sencha is now your $PATH, add, for example, this to your ~/.bashrc
export PATH=$PATH:~/sencha/cmd/6.0.2.14/bin
You need to find the correct path yourlself. That should do the trick.

How do I check if the Java JDK is installed on Mac?

How do you check if Java SDK is installed on a Mac?
Is there a command line for this?
javac -version in a terminal will do
You can leverage the java_home helper binary on OS X for what you're looking for.
To list all versions of installed JDK:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.0_51, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
1.7.0_79, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
To request the JAVA_HOME path of a specific JDK version, you can do:
$ /usr/libexec/java_home -v 1.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
$ /usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
You could take advantage of the above commands in your script like this:
REQUESTED_JAVA_VERSION="1.7"
if POSSIBLE_JAVA_HOME="$(/usr/libexec/java_home -v $REQUESTED_JAVA_VERSION 2>/dev/null)"; then
# Do this if you want to export JAVA_HOME
export JAVA_HOME="$POSSIBLE_JAVA_HOME"
echo "Java SDK is installed"
else
echo "Did not find any installed JDK for version $REQUESTED_JAVA_VERSION"
fi
You might be able to do if-else and check for multiple different versions of java as well.
If you prefer XML output, java_home also has a -X option to output in XML.
$ /usr/libexec/java_home --help
Usage: java_home [options...]
Returns the path to a Java home directory from the current user's settings.
Options:
[-v/--version <version>] Filter Java versions in the "JVMVersion" form 1.X(+ or *).
[-a/--arch <architecture>] Filter JVMs matching architecture (i386, x86_64, etc).
[-d/--datamodel <datamodel>] Filter JVMs capable of -d32 or -d64
[-t/--task <task>] Use the JVM list for a specific task (Applets, WebStart, BundledApp, JNI, or CommandLine)
[-F/--failfast] Fail when filters return no JVMs, do not continue with default.
[ --exec <command> ...] Execute the $JAVA_HOME/bin/<command> with the remaining arguments.
[-R/--request] Request installation of a Java Runtime if not installed.
[-X/--xml] Print full JVM list and additional data as XML plist.
[-V/--verbose] Print full JVM list with architectures.
[-h/--help] This usage information.
Type in a terminal:
which javac
It should show you something like
/usr/bin/javac
Below command worked out pretty good:
javac -version
I also manually verified by navigating to the Java Folder on my Mac
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk
/usr/bin/java_home tool returns 1 if java not installed.
So you can check if java is installed by the next way:
/usr/libexec/java_home &> /dev/null && echo "installed" || echo "not installed"
Open terminal.
run command to see:
javac -version
Also you can verify manually by going to the specific location and then check. To do this run below command in the mac terminal
cd /Library/Java/JavaVirtualMachines/
Then run ls command in the terminal again. Now you can see the jdk version & package if exists in your computer.
If you are on Mac OS Big Sur, then you probably have a messed up java installation.
I found info on how to fix the issue with this article:
https://knasmueller.net/how-to-install-java-openjdk-15-on-macos-big-sur
Download the .tar.gz file of the JDK on https://jdk.java.net/15/
Navigate to the download folder, and run these commands (move the .tar.gz file, extract it and remove it after extraction):
sudo mv openjdk-15.0.2_osx-x64_bin.tar.gz /Library/Java/JavaVirtualMachines/
cd /Library/Java/JavaVirtualMachines/
sudo tar -xzf openjdk-15.0.2_osx-x64_bin.tar.gz
sudo rm openjdk-15.0.2_osx-x64_bin.tar.gz
Note: it might be 15.0.3 or higher, depending on the date of your download.
run /usr/libexec/java_home -v15 and copy the output
add this line to your .bash_profile or .zshrc file, depending on which shell you are using. You will probably have only one of these files existing in your home directory (~/.bash_profile or ~/.zshrc).
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home
save the changes and make them effective right away by running:
source ~/.bash_profile or source ~/.zshrc
check that java is working - run java -v
Just type javac. If it is installed you get usage information, otherwise it would just ask if you would like to install Java.
Make sure you correctly define the project's JDK and restart IntelliJ (full restart).
On MAC find your JDK path by executing the command.
/usr/libexec/java_home

Resources