How can I control the Java version used with Ammonite - scala

In my Linux system I have several Java versions installed.
How can I control the version used to launch an Ammonite script?

The amm executable is a sh script.
It searches java in the PATH.
So you can change temporarily your PATH. In bash it can be done in this way:
PATH=/path/to/java myscript.sc argument1 argument2 ....

Related

Compiling via Perl Packager including libraries?

I recently compiled a perl script using "pp" (Perl Packager) on an x86 linux box running Manjaro. I had someone test it on their x86 Debian 10 box, but it wouldn't run.
He said that since Libperl.so has a dependence on glibc v2.29. Since his OS release only allows up to a v2.28, that it's preventing it from executing.
Is there a way for me to compile my script with my version of the libraries so it will run on any x86 linux machine?
I ran the following command to compile my code:
pp -o oag1025 oag1025.pl
I tried using some of the options outlined here, but I couldn't get anywhere:
http://perl.mines-albi.fr/perl5.8.5/site_perl/5.8.5/pp.html

Does anyone know how to run the scala executable in Git Bash shell?

I have installed Scala on my Windows 7 system. When I run "scala -version" from the Windows command prompt, I get:
Scala code runner version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
When I run "scala -version" from a Git Bash shell, required by Swagger and other frameworks, I get:
Error: Could not find or load main class Files
Does anyone know how to run the scala executable from a Git Bash shell?
I'm guessing that you've installed Scala on C:\Program Files (x86) or C:\Program Files. As far as I can tell, git bash has problems reading the classpath if it has spaces and/or "()" in it.
If you're on a Win7 64-bit system, the easiest thing for you is:
Edit the system variables PATH
Find the scala\bin entry
Replace the C:\Program Files with Progra~1 or C:\Program Files (x86) with Progra~2
If you're not on a 64-bit system, (which I can't verify due to not having one), you'll have to do some escaping so that PATH isn't screwed up with the spaces and/or ().
EDIT: Here's a related SO but with Play instead: Play 2.0-RC3 -- Error: Could not find or load main class
Install scala with Coursier and run the scala.bat command from git bash terminal

How to reconfigure version of scala on ubuntu?

I installed scala with apt-get install scala. ans figure out another trouble where exactly scala home is now?
this Where is SCALA_HOME on Ubuntu? question suggest:
/usr/share/java
I want to be sure and downloaded and untarred last scala version.
all this I put at /opt/scala and added to system environment.
But now I have default installed version of scala. I don't know how to set version to new location?
Here is how it looks:
nazar#nazar-desktop:~$ scala -version
Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
nazar#nazar-desktop:~$ echo $SCALA_HOME
/opt/scala/scala-2.10.3
I want to turn installed version from 2.9.2 to untarred one.
how to solve this trouble?
I personally wouldn't bother.
The binary incompatibilities across major versions mean you'll likely want more than one version available if you ever work on more than one project.
My advice is to install the latest version of SBT and use that to manage versions at a per-project level. You'll still be able to get a REPL via sbt console
If you put $SCALA_HOME/bin at the front of your PATH variable, like this:
export PATH="$SCALA_HOME/bin:$PATH"
that should fix it.
However, you need to type hash -r in each terminal window in which you have tried to run scala, to make the change take effect.
I untarred scala in /usr/local then made scala a symbolic link to scala-2.10.0
The reason for this is to make an upgrade easier, just alter the symlink
Next, I added /usr/local/scala/bin to the PATH in .bashrc
After this, typing scala in a term gives me the prompt
To install scala into eclipse was considerably more complicated but I got that to work too, by untarring stuff into /usr/local
I didn't bother with apt-get on .deb packages as I run Ubuntu LTS and as far as I know there are no ppa that track a current version
Also, this SCALA_HOME thing: there is a function in the shell script "scala" that finds it in this way
findScalaHome () {
# see SI-2092 and SI-5792
local source="${BASH_SOURCE[0]}"
while [ -h "$source" ] ; do
local linked="$(readlink "$source")"
local dir="$( cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pw
d )"
source="$dir/$(basename "$linked")"
done
( cd -P "$(dirname "$source")/.." && pwd )
}

How to set properly SCALA_HOME in a macport installed scala

I have installed multiple versions of Scala (2.9 and 2.10) on my mac (OS X 10.7.5) using macports. I like this way because can switch easily between these two versions by the simple "port select" command.
But, the SCALA_HOME environment variable does not get set automatically with this command.
Is there a proper nice macport command to set correctly the SCALA_HOME variable?
If no, what directory should the SCALA_HOME point to in a macport installed scala?
Thanks
EDIT:
Until now the best way I found is with a shell script that looks what is the current scala command and adjust the SCALA_HOME variable accordingly. I run it always after switching the Scala version.
Here is the important command in the script. I'm not an expert shell programmer, therefore I'll be thankful for any suggestion:
export SCALA_HOME=$(ls -l `which scala` | gawk 'match($0, "(/opt/local/share/.*)/bin/scala", a) {print a[1]}')
I don't know of a way to have MacPorts do it for you, but Scala is installed at /opt/local/share/scala-2.10/ for me. So I added
export SCALA_HOME="/opt/local/share/scala-2.10/"
to my ~/.profile and everything seems to be working for me now (although you'd have to switch change your $SCALA_HOME every time you switch versions).
OK, until now the best solution I found is to run following command after changing scala version:
export SCALA_HOME=$(ls -l `which scala` | gawk 'match($0, "(/opt/local/share/.*)/bin/scala", a) {print a[1]}')
I have included that command also in my .bash_profile so my SCALA_HOME always points to the scala version I am using currently.
This command uses gawk 4.1.1 installed from MacPorts.
Currently when scala is installed via brew it's path set to
/usr/local/Cellar/scala/[version]
So SCALA_HOME could be defined as follows:
export SCALA_HOME=$(greadlink -f $(dirname "$(greadlink -f $(which scala))")/../../)
p.s: You need to install 'greadlink' for that since the regular readlink doesn't support the 'f' flag.
if you are installing the versions with home brew you can simply:
brew switch scala 2.10.3

How to override system commands in shells initiated by Perl?

I am trying to install CPAN modules on shared Linux environment without root privileges, and in particular the PDL::Graphics::Gnuplot module. The default gnuplot version is Version 3.7 patchlevel 3, but the version Version 4.6 patchlevel 3 is also installed (/opt/gnuplot-4.6.3/bin/gnuplot). When trying to install the Perl module in my local directory, it fails on the test:
unless(`gnuplot -V`)
I tried to override the default gnuplot command with an alias in .bashrc:
alias gnuplot='/opt/gnuplot-4.6.3/bin/gnuplot'
In the regular shell I get:
$gnuplot -V
gnuplot 4.6 patchlevel 3
But using Perl:
$ perl -e 'system("gnuplot -V")'
Cannot open load file '-V'
line 0: (No such file or directory)
How do I make Perl to see the new version of gnuplot?
On solution I think of is to change the system command in the Makefile and in the following files in the module.
Shell aliases only work in the interactive shell. You have other options:
Change your PATH so that the newer gnuplot's bin precedes the old one.
Make a symbolic link to the new gnuplot from your bin and make sure it comes first in PATH.