My Ubuntu machine has two user (root and Bikram) and tmp folder has following permission.

**drwxr-xr-x   1 root root  tmp**

Now I have tried to run helloworld.scala (Console.println("Hello, world!")) program with the Bikram user in console

$scala helloworld.scala

But it has thrown following exception

java.io.IOException: Permission denied
    at java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.io.File.createTempFile(File.java:2024)
    at scala.reflect.io.File$.makeTemp(File.scala:29)
    at scala.reflect.io.Directory$.makeTemp(Directory.scala:27)
    at scala.tools.nsc.ScriptRunner.compile$1(ScriptRunner.scala:93)
    at scala.tools.nsc.ScriptRunner.$anonfun$withCompiledScript$2(ScriptRunner.scala:156)
    at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:124)
    at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:200)
    at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:63)
    at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:88)
    at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:99)
    at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:104)
    at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

Same program I have run again with root user it works and inside the tmp folder scala-develroot is created.

So how to handle this issue? I don't want to use root as a user and also I can't change the tmp folder permission. Is there any way to specify a directory to write scala-develroot ?

Note : 
root@1a8048217a8f:/tmp# scala -version
Scala code runner version 2.12.2 -- Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc.

Thanks in advance.

1

There are 1 answers

0
Ramesh Maharjan On

You must be running scala helloworld.scala staying inside /tmp directory which only root has access to. The solutions to your problem is to copy helloworld.scala to any other directory where user Bikram has access to. And run the command staying in that directory.

Note that scala executable should be present as environment variable for user Bikram and SCALA_HOME variable must be set for user Bikram

Moreover you can give sudo(root) access to user Bikram by doing sudo usermod -a -G sudo Bikram