Question

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]}')

Was it helpful?

Solution 2

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.

OTHER TIPS

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).

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top