Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update Scala Version in Ubuntu

In Ubuntu terminal when I write the command below:

scala -version

It gives the following Output:

Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL

I want to update this to 2.11.8. I downloaded the tar file

scala-2.11.8.tgz

and untared it to get

scala-2.11.8

folder in "/home/hdadmin/" location.

But still when I check the scala-version again it shows the same 2.9.2 version. It is picking scala version from

/usr/bin/scala

instead of

/home/hdadmin/scala-2.11.8

Is there a way to change this path?

I tried uninstalling & reinstalling scala using commands below:

sudo apt-get remove scala
sudo apt-get remove scala-library scala
sudo apt-get install scala

But the same version(2.9.2) gets installed because I think it comes by default with Java(1.8) that I have. There are some very unclear option online to update using sbt or deb or in the link http://osgux.tumblr.com/post/44635945407/install-scala-2-10-0-in-ubuntu.

I need to know if there is a direct way to update scala version.

like image 432
Vishal Sharma Avatar asked May 19 '17 16:05

Vishal Sharma


People also ask

How do I install latest version of Scala?

Install it on your system with the following instructions. Download and execute the Scala installer for Windows based on Coursier, and follow the on-screen instructions. JavaScript is disabled, click the tab relevant for your OS. Follow the documentation from Coursier on how to install and run cs setup .

What is the latest version of Scala?

Current 2.13. x release: Scala 2.13. 8 - Released on January 12, 2022.

How do I know my Scala version?

Check Scala Version Using scala Command Write the scala command to your terminal and press enter. After that, it opens Scala interpreter with a welcome message and Scala version and JVM details.


2 Answers

If you want to remove the old scala from your computer, you have to delete the previously extracted scala folder. To know the path to old scala

which scala

It will show you the path upto ..../bin/scala
You can delete the parent folder (before bin folder) to remove the old scala.
For the new scala to be recognized by the system, the executable binary file path need to be put in PATH of the system if you haven't done so. Or you need to edit the path to point to the new scala. As @Mureinik suggested, you need to set two variables in ~/.bashrc file

export SCALA_HOME=/home/hdadmin/scala-2.11.8

And

export PATH=$PATH:$SCALA_HOME/bin

Then either you restart your terminal or do one of the following commands

source ~/.bashrc

Or

. ~/.bashrc

Now

scala -version

should show you the right version.

like image 170
Ramesh Maharjan Avatar answered Oct 21 '22 21:10

Ramesh Maharjan


You need to add /home/hdadmin/scala-2.11.8 at the beginning of your $PATH, so the executable is taken from there first:

export PATH=/home/hdadmin/scala-2.11.8:${PATH}

You can place this call in your .bashrc (or the equivalent in your own environment if you aren't using bash).

like image 35
Mureinik Avatar answered Oct 21 '22 21:10

Mureinik