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
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:
sudo nano /etc/paths
and add this line to the end:
/usr/bin/scala-2.11.2/bin
Press Ctrl+X to exit nano and answer "Yes" when prompted to overwrite the file
Then restart Terminal and once you type:
scala
you will get the scala command line that looks like this:
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
I hope this helps.
You need to add scala\bin
to your PATH
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):
echo 'export PATH=/Users/<your username>/scala/bin:$PATH' >> ~/.bash_profile
then close the Terminal and start it again.
Scala recommends using Homebrew to install the Typesafe stack for Scala 2.9.2.
brew install scala sbt maven giter8
Homebrew will install soft links in /usr/local/bin
for sbt
, scala
, scalac
, scaladoc
, scalap
, fsc
and g8
. Follow the soft links to its final referent in order to determine where $SCALA_HOME needs to be. $SCALA_HOME should contain bin/scala
and lib/scala-compiler.jar
.
Typesafe recommends using sbt console
instead of scala
to get the interpreter going, because sbt
will also manage library dependencies to libraries such as Akka. That said, if you want to use scala
, scalac
, fsc
, scalac
and scaladoc
directly, you may need to run a chmod +x
on the referents of the soft links.
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.
ln -s /opt/scala-2.9.0-1/bin/scala /usr/local/bin
Now just type scala
in the terminal and you're all set.
This way you don't have to set your PATH
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 terminal
ln -s /opt/scala-2.9.1/bin/scala /usr/local/bin/scala2.9.1
Now, 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
ln -s /opt/scala-2.9.0-1/bin/scalac /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/scalap /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/scaladoc /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/fsc /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/sbaz /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/sbaz-setup /usr/local/bin
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 a brew 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.
Just install Scala with : $ brew install scala
so you can use $scala
in terminal to evaluate scala instructions , for now the official Scala website recommend installing scala with sbt : $ brew install sbt
which won't let you scala
keyword in terminal