I'm very new to Scala. I have downloaded it, got it working in Eclipse where I'll be developing it; but I can't make it work in Terminal.
All sites and books say to just type scala
- this doesn't work.
The website infuriatingly says:
We assume that both the Scala software and the user environment are set up correctly.
How do I do that bit?
I'm very new to this, and using Jargon or assuming too much knowledge of frameworks around Scala will ruin a good response; please keep it simple.
- Mac OS X (10.6.7)
- Scala: 2.9.0.1
Thank you
Scala recommends using Homebrew to install the Typesafe stack for Scala 2.9.2.
Homebrew will install soft links in
/usr/local/bin
forsbt
,scala
,scalac
,scaladoc
,scalap
,fsc
andg8
. Follow the soft links to its final referent in order to determine where $SCALA_HOME needs to be. $SCALA_HOME should containbin/scala
andlib/scala-compiler.jar
.Typesafe recommends using
sbt console
instead ofscala
to get the interpreter going, becausesbt
will also manage library dependencies to libraries such as Akka. That said, if you want to usescala
,scalac
,fsc
,scalac
andscaladoc
directly, you may need to run achmod +x
on the referents of the soft links.You need to add
scala\bin
to yourPATH
environment variable.On Mac OS X the path to Scala bin is usually:
/Users/<your username>/scala/bin
and on Windows usually:C:\Program Files (x86)\scala\bin
.On Mac OS X use the Terminal and write (using your username):
then close the Terminal and start it again.
For OS X, I highly recommend Homebrew.
The installation of Homebrew is incredibly easy. Once installed, you just need to run
brew install scala
and scala will be installed and ready to go. Homebrew also has tons of other goodies just abrew install
away.If you don't already have Java installed, you can install that with
brew cask install java
.MacPorts or Fink may have something similar, but I prefer Homebrew.
Not a big fan of cluttering up my
PATH
variable. I just symlink all my programs to /usr/local/bin, which is in the classpath. For example, if you downloaded scala and uncompress it in /opt/scala-2.9.0-1, run the following in the terminal.Now just type
scala
in the terminal and you're all set. This way you don't have to set yourPATH
or change it when you have a new version of scala you want to try out. If you download a new version, you can uncompress it in any location and symlink the new version. Say you download version 2.9.1 and uncompress it in /opt/scala-2.9.1. You can type the following in the terminalNow, to use scala 2.9.1 you just run
scala2.9.1
at the terminal. When you are ready to switch to 2.9.1 fulltime, just update the symlink.You could also add scaladoc, scalac, scalap and others in the same way
If you downloaded scala with macports try typing scala-2.9 (or whatever is the filename of the contents of folder /opt/local/bin/scala/)
(At least this works for OSX mountain lion)
My way of making Scala run every time you type "scala" in Terminal was to add the path not to the .bashrc file but to the /etc/paths one.
Then open the /etc/paths file with nano:
and add this line to the end:
Press Ctrl+X to exit nano and answer "Yes" when prompted to overwrite the file
Then restart Terminal and once you type:
you will get the scala command line that looks like this:
I hope this helps.