38

I am using Ubuntu 18.04 + Scala 2.11.12 (OpenJDK 64-Bit Server VM, Java 1.8.0_162).

Once I open the scala shell, I am not able to see anything that I type. It gets typed though.

Below is how it is happening when I type println("Hello, world!") at console:

$ scala 
Welcome to Scala 2.11.12 (OpenJDK 64-Bit Server VM, Java 1.8.0_162).
Type in expressions for evaluation. Or try :help.

scala> Hello, world!

scala>

Any ideas on how we can get through?

Abhay Dandekar
  • 1,230
  • 10
  • 30
  • The following solution to a different issue solved this problem for me: https://stackoverflow.com/a/44361749/2449365. I'm not sure how/if the problems are related, but maybe this will help shed light on the issue. – Ben Apr 01 '19 at 22:21

6 Answers6

72

To fix the problem in the current scala repl session run:

import sys.process._
"reset" !

To fix the problem completely removed scala and install it with dpkg (not with apt):

sudo apt-get remove scala-library scala
sudo wget www.scala-lang.org/files/archive/scala-2.11.12.deb
sudo dpkg -i scala-2.11.12.deb
mgershen
  • 1,567
  • 16
  • 22
  • Oh Let me try that ... :) – Abhay Dandekar Jul 31 '18 at 12:57
  • 1
    Cool, this is working for me! ... I guess, it was scala setup issue with system group and system user, scala. Thanks a bunch! – Abhay Dandekar Jul 31 '18 at 13:09
  • 1
    nice. this process also gives the REPL fancy colours! v important – joel Aug 20 '18 at 22:19
  • 1
    Notice that this scala package is incompatible with OpenJDK due to https://issues.scala-lang.org/browse/SI-10098. It will output `cat: /usr/lib/jvm/java-8-openjdk-amd64/release: No such file or directory`. – Fernando Correia Nov 21 '18 at 18:50
  • 2
    Though both the mentioned solutions work, what is the cause of the issue? Is there a bug with the scala REPL functionality or apt way installing scala? – nashter Aug 03 '19 at 09:40
  • I used the code above, but replaced the version to 2.13.1 I'm using Pop OS 18.04 (similar to Ubuntu 18.04) – Alex Lamson Mar 14 '20 at 22:15
18

The following thing is working for me.

  1. Start sbt
  2. Open a scala console via sbt.

    ~$ sbt
        [info] Loading project definition from /home/abhay/project
        [info] Set current project to abhay (in build file:/home/abhay/)
        [warn] sbt server could not start because there's another instance of sbt running on this build.
        [warn] Running multiple instances is unsupported
        sbt:abhay> console
        [info] Starting scala interpreter...
        Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_161).
        Type in expressions for evaluation. Or try :help.
        scala> printf("Hello, Abhay!"); 
        Hello, Abhay!
        scala>
    

This is working for me for now.

I am pretty sure its some environment issue. Anyone else facing something similar?

~Abhay

Abhay Dandekar
  • 1,230
  • 10
  • 30
  • Thank you so much for posting this. I hit the same issue and cant seem to figure out why this occurs. A google search hits to your post and kudos to you for posting this as I was breaking my head why this stopped working after the upgrade. And even a complete reinstall doesnt help. – Kabeer Ahmed Apr 28 '18 at 19:08
  • I am glad that this came in handy .. :) ... just in case you figure out how to make it work without sbt, do share it across. Thanks – Abhay Dandekar May 01 '18 at 03:20
  • 1
    This works for me, but interestingly once I quite the console, the originally described problem returns, i.e. I can't see anything I type. – Jonathan Crosmer May 17 '18 at 12:53
11

scala 2.11.12 as described above throws some error before the REPL is started, which is taken care in scala 2.12.x Instead remove Scala and Install the latest scala package with dpkg

sudo apt-get remove scala-library scala
sudo wget www.scala-lang.org/files/archive/scala-2.12.8.deb
sudo dpkg -i scala-2.12.8.deb
Rahul Khanna
  • 316
  • 3
  • 12
  • 2
    This is the cleanest solution in my view. I only want to add that just a few hours ago both the deb and rpm packages for Scala version 2.13.0 have been released to the public. Therefore, unless you have a specific reason for installing version 2.12.x, I would suggest that everyone goes directly for 2.13.0 with `sudo wget www.scala-lang.org/files/archive/scala-2.13.0.deb` etc. – Sal Borrelli Jun 07 '19 at 16:04
1

This worked for me!

Ubuntu steps: 1. Go to /usr/share/sbt/bin 2. Open file "sbt" 3. Add "export TERM=xterm-color" right below "#!/bin/sh"

OS X steps: 1. Go to /usr/local/bin/ 2. Open file "sbt" 3. Add "export TERM=xterm-color" right below "#!/bin/sh"

Oscar Drai
  • 141
  • 1
  • 7
1

Install SBT:

echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
sudo apt-get update
sudo apt-get install sbt

Then Type sbt on the command prompt:enter image description here

Then Type console enter image description here

Good to go.

Test: type: printf("Hello Scala")

enter image description here

Cheers!!!

prashant.kr.mod
  • 1,178
  • 13
  • 28
0

This seems to be an issue with JLine2 being built with JDK9+, but being used on JSK8.

JLine is a Java library for handling console input.

just download and install via dpkg:

https://launchpad.net/~lokkju/+archive/ubuntu/java-compat/+build/16458066/+files/libjline2-java_2.14.6-1ubuntu1~bionicppa1_all.deb

TrevorDeTutor
  • 683
  • 6
  • 11