Ubuntu安装PyCharm

1. 下载

http://www.jetbrains.com/pycharm/download/

选择Linux Tab,选择下载免费的Community Edition【1】。当前版本是3.4

2. 安装PyCharm

按照官网给出的安装指导【2】进行安装。

(1) Copy the pycharm-*.tar.gz to the desired installation location (make sure you have rw permissions for that directory)

$ cd Downloads/

(2)Unpack the pycharm-.tar.gz using the following command: tar xfz pycharm-.tar.gz

$ tar xfz pycharm-*.tar.gz

(3)Remove the pycharm-*.tar.gz to save disk space (optional)

$ rm pycharm-*.tar.gz

(4)Run pycharm.sh from the bin subdirectory

$ cd pycharm-community-3.4.1/bin/

$ ./pycharm.sh

但是安装开始,出现如下错误:

ERROR: Cannot start PyCharm

No JDK found. Please validate either PYCHARM_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation.

打开pycharm.ch文件查看,发现报错的地方在:

message()
{
  TITLE

="Cannot start PyCharm"

  if [ -t 1 ]; then
    echo "ERROR: $TITLE\n$1"
  elif [ -n `which zenity` ]; then
    zenity --error --title="$TITLE" --text="$1"
  elif [ -n `which kdialog` ]; then
    kdialog --error --title "$TITLE" "$1"
  elif [ -n `which xmessage` ]; then
    xmessage -center "ERROR: $TITLE: $1"
  elif [ -n `which notify-send` ]; then
    notify-send "ERROR: $TITLE: $1"
  else


echo "ERROR: $TITLE\n$1"

  fi
}

# ---------------------------------------------------------------------
# Locate a JDK installation directory which will be used to run the IDE.
# Try (in order): PYCHARM_JDK, JDK_HOME, JAVA_HOME, "java" in PATH.
# ---------------------------------------------------------------------
if [ -n "$PYCHARM_JDK" -a -x "$PYCHARM_JDK/bin/java" ]; then
  JDK="$PYCHARM_JDK"
elif [ -n "$JDK_HOME" -a -x "$JDK_HOME/bin/java" ]; then
  JDK="$JDK_HOME"
elif [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
  JDK="$JAVA_HOME"
else
  JAVA_BIN_PATH=`which java`
  if [ -n "$JAVA_BIN_PATH" ]; then
    if [ "$OS_TYPE" = "FreeBSD" -o "$OS_TYPE" = "MidnightBSD" ]; then
      JAVA_LOCATION=`JAVAVM_DRYRUN=yes java | "$GREP" '^JAVA_HOME' | "$CUT" -c11-`
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    elif [ "$OS_TYPE" = "SunOS" ]; then
      JAVA_LOCATION="/usr/jdk/latest"
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    elif [ "$OS_TYPE" = "Darwin" ]; then
      JAVA_LOCATION=`/usr/libexec/java_home`
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    fi

    if [ -z "$JDK" -a -x "$READLINK" -a -x "$XARGS" -a -x "$DIRNAME" ]; then
      JAVA_LOCATION=`"$READLINK" -f "$JAVA_BIN_PATH"`
      case "$JAVA_LOCATION" in
        */jre/bin/java)
          JAVA_LOCATION=`echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME"`
          if [ ! -d "$JAVA_LOCATION/bin" ]; then
            JAVA_LOCATION="$JAVA_LOCATION/jre"
          fi
          ;;
        *)
          JAVA_LOCATION=`echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME"`
          ;;
      esac
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    fi
  fi
fi

if [ 

-z "$JDK"

 ]; then
  message 

"No JDK found. Please validate either PYCHARM_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation."


  exit 1
fi

说明没有找到JDK location path。需要安装并配置JDK了。

3. 安装JDK

首先查了一下Ubuntu12.04是否支持JDK8,发现还是支持的。那就放心安装吧。

参照【3】的方法,通过设置源仓库的方式安装。(如果想手动安装,请参考【5】【6】)

Important: This PPA supports Ubuntu 14.04, 13.10, 12.04 and 10.04 as well as the corresponding Linux Mint versions. Ubuntu 13.04 and 12.10 are no longer supported by Canonical

(1)返回到Home目录:“~”,然后依次执行一下几条command

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

安装过程中会跳出Oracle license对话框,选择接受就是了。

(2)安装完成后,运行”java -version”或者”javac -version”查看是否安装成功。如果得到类似如下的输出,表明安装成功了。

$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
$ javac -version
javac 1.8.0_20

(3) 在【3】中说道,如果想automatically set up the Java 8 environment variables,可以使用下面的command:

http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

sudo apt-get install oracle-java8-set-default

我使用该command后,在Terminal中运行 echo $JAVA_HOME,没有任何输出。看来是没起什么作用。有可能是在一开始配置完repository后,安装时使用该条命令,可以以后尝试一下。

UPDATED: 使用 sudo apt-get install oracle-java8-set-default,测试echo $JAVA_HOME,仍然是没有$JAVA_HOME环境变量的。还是需要手动设置。

由于一些程序在运行时可能默认需要 $JAVA_HOME 环境变量,因此还是需要设置一下环境变量的。

4. 配置$JAVA_HOME 环境变量

参考【4】中 Setting the “JAVA_HOME” environment variable 一节进行设置。

(1)Find out the path of your Java installation:

sudo update-alternatives --config java

它将返回类似如下的结果,列出了本机所安装的所有Java运行时环境JRE。(共有2个:JDK7和OpenJDK6,0和2是同一个,auto mode和manual mode的差别)
复制代码

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:

复制代码

对应的各个JRE的 安装路径分别为:

  1. /usr/lib/jvm/java-7-oracle

  2. /usr/lib/jvm/java-6-openjdk-amd64

  3. /usr/lib/jvm/java-7-oracle

在我本机 执行 sudo update-alternatives –config java 的结果为:

Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java   1         auto mode
* 1            /usr/lib/jvm/java-8-oracle/jre/bin/java   1         manual mode

Press enter to keep the current choice[*], or type selection number:

可见只安装了一个Java环境: JDK8。它对应的安装路径为:

/usr/lib/jvm/java-8-oracle

(2)编辑/etc/environment文件

sudo nano /etc/environment

复制上面的路径 /usr/lib/jvm/java-8-oracle,添加如下一行

JAVA_HOME="/usr/lib/jvm/java-8-oracle"

(3) Reload该文件,使之立即生效,而不必注销并重新登录

source /etc/environment

(4)使用下面的命令测试

echo $JAVA_HOME

会输出刚才所设置的路径 /usr/lib/jvm/java-8-oracle。

5. 再次安装PyCharm

(1)cd到Downloads/pycharm-community-3.4.1/bin/目录,执行./pycharm.sh。询问是否导入settings,选择不导入->OK

后面省略了就。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值