19

I am new to Ubuntu. I want to install the latest Scala version 2.11.4 on my machine but the instructions on their website are cryptic to me. Can any one explain how to install it step by step?

1

4 Answers 4

17

The easiest way to install Scala would be to use the .deb installation file. On the download page you can see the newest stable version. Then go to the All Downloads page and find that version (or Scala 2.11.4). Scroll down to the bottom of that version's page and look for scala-2.11.4.deb (or the appropriate version) and download it.

If you're comfortable with the command line, you can install the downloaded Scala deb with:

sudo dpkg -i scala-2.11.4.deb

Otherwise, you're going to have to install GDebi through either the Ubuntu Software Center, or via a terminal with:

sudo apt-get install gdebi

Once GDebi is installed, you can double click scala-2.11.4.deb in your file browser which will open the package installer. Finally, click "Install Package", and your new version of Scala will be installed.

2
  • 1
    +1 Thanks for pointing out that they provide .deb files. However, you don't need gdebi, it's as simple as: sudo dpkg -i scala-2.11.4.deb
    – Stephen
    Apr 27, 2015 at 22:33
  • 1
    I couldn't find them at that link, but they are at the archives page: scala-lang.org/files/archive Jul 19, 2016 at 15:18
11

Just download scala.deb and install it:

sudo apt-get remove scala-library scala
wget http://www.scala-lang.org/files/archive/scala-2.11.6.deb
sudo dpkg -i scala-2.11.6.deb
sudo apt-get update
4
  • sudo dpkg -i scala-2.11.4.deb should be sudo dpkg -i scala-2.11.6.deb Jul 5, 2015 at 6:42
  • 2
    I don't think scala needs to be installed twice again using sudo apt-get install scala. dpkg will install it. Jul 23, 2015 at 9:38
  • 1
    @PraveenSripati I'm not sure why he put sudo apt-get install scala, as sudo dpkg -i scala-2.11.6.deb is sufficent but installing the scala.deb from the site I think is better than using sudo apt-get install scala, as the official repositories are more up to date Sep 9, 2015 at 12:04
  • I got dpkg-deb: error: `scala-2.11.6.deb' is not a debian format archive
    – amit_kumar
    May 20, 2016 at 13:06
3

Installing scala 2.11.4 or any other version that is not in the Ubuntu repository or a PPA (mind though: scala will require JAVA and I assume you have this installed already. See the ubuntu help if you have not).

  • download the file.
  • Extract the contents to somewhere on your system. I would opt for /opt/scala/. Something like:

    tar xvfz ~/Downloads/scala-2.11.4.tgz /opt/ mv /opt/scala-2.11.4/ /opt/scala/

  • The readme in "docs" state you can run scala from the bin directory:

Installation

Decompress the archive and run the above commands directly from bin directory. We recommend adding the full path of the bin directory to the PATH environment variable.

  • ... where you have the following tools:

    - scala       Scala interactive interpreter
    - scalac      Scala compiler
    - fsc         Scala resident compiler
    - scaladoc    Scala API documentation generator
    - scalap      Scala classfile decoder
    

    So you would do

    cd /opt/scala
    scala
    

    to open the interpreter.


  • Regarding the PATH mentioned in the read me:

    Add Scala to your $PATH by adding this line to .profile inside your home directory

    PATH="$PATH:/opt/scala/bin"
    

    Mind that the path name needs to be named after what you extracted it too. Adding it would stop the need to do cd /opt/scala/ and you can envoke scala from anywhere on your system.

0

Yes, the installation instructions on scala-lang.org are brief and assume a certain level of proficiency with setting up of environment variables. This assumption is also present in most of the answers here or on stackoverflow. another reson I wanted to add my answer is that there are no more .deb files available for downloading from scala-lang.org.

Recently I have successfully installed Scala 2.11.7 on my machine following these steps. It was a fresh Scala installation and Java 1.8 was already present.

  1. Downloaded scala-2.11.7.tgz from http://www.scala-lang.org/download/ to my Downloads directory.

  2. Navigate to the downloads directory and unpack the archive:

    sudo tar xvfz scala-2.11.4.tgz
    
  3. Move the unpacked directory to the directory indicated in the instructions:

    mv scala-2.11.7 /usr/local/share/scala
    
  4. Set the environment variables permanently. As indicated in the question on Stack Overflow here, and used by other software package installations, (e. g. I found Anaconda Python as the last automatic edit on it), one of reliable ways of doing it is by editing .bashrc file or adding these variables to the PATH directly with these commands:

    export 'SCALA_HOME="/usr/local/share/scala"' >> ~/.bashrc
    
    export 'PATH="$PATH:$SCALA_HOME/bin"' >> ~/.bashrc
    
  5. Reload the shell for the changes to take effect:

    exec $SHELL
    

Now you can start Scala REPL from the command line by typing:

scala 
3
  • I guess you don't need sudo in step 2, but maybe in step 3. And you also don't need sudo for editing your .bashrc
    – Wayne_Yux
    Jan 6, 2016 at 13:27
  • One more thing to have in mind is that your sudo password is valid for 15 more min after the first submission. From Ubuntu docs, help.ubuntu.com/community/RootSudo . Jan 6, 2016 at 15:11
  • I just edited by .bashrc directly with the line: export PATH="/opt/scala/scala-2.12.1/bin:$PATH"
    – wayneeusa
    Dec 28, 2016 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .