First check the log file after spark-shell command run
whether SparkContext is initinalized as sc.
if SparkContext is not initialized properly
you have to set the IP address in spark environment.
Open the env file in conf/spark.env.sh and add the below line
export SPARK_LOCAL_IP="127.0.0.1"