如何在 Ubuntu 15.04 / CentOS 7 上安装 Android Studio
随着最近几年智能手机的进步,安卓成为了最大的手机平台之一,在开发安卓应用中所用到的所有工具也都可以免费得到。Android Studio 是基于 IntelliJ IDEA 用于开发安卓应用的集成开发环境(IDE)。它是 Google 2014 年发布的免费开源软件,继 Eclipse 之后成为主要的 IDE。
在这篇文章,我们一起来学习如何在 Ubuntu 15.04 和 CentOS 7 上安装 Android Studio。
在 Ubuntu 15.04 上安装
我们可以用两种方式安装 Android Studio。第一种是配置所需的库然后再安装它;另一种是从 Android 官方网站下载然后在本地编译安装。在下面的例子中,我们会使用命令行设置库并安装它。在继续下一步之前,我们需要确保我们已经安装了 JDK 1.6 或者更新版本。
这里,我打算安装 JDK 1.8。
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> add</span><span class="pun">-</span><span class="pln">apt</span><span class="pun">-</span><span class="pln">repository ppa</span><span class="pun">:</span><span class="pln">webupd8team</span><span class="pun">/</span><span class="pln">java</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">apt-get</span><span class="pln"> update</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">apt-get</span><span class="pln"> install Oracle</span><span class="pun">-</span><span class="pln">java8</span><span class="pun">-</span><span class="pln">installer oracle</span><span class="pun">-</span><span class="pln">java8</span><span class="pun">-</span><span class="kwd">set</span><span class="pun">-</span><span class="kwd">default</span>
验证 java 是否安装成功:
<span class="pln">poornima@poornima</span><span class="pun">-</span><span class="typ">Lenovo</span><span class="pun">:~</span><span class="pln">$ java </span><span class="pun">-</span><span class="pln">version</span>
现在,设置安装 Android Studio 需要的库
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt</span><span class="pun">-</span><span class="pln">add</span><span class="pun">-</span><span class="pln">repository ppa</span><span class="pun">:</span><span class="pln">paolorotolo</span><span class="pun">/</span><span class="pln">android</span><span class="pun">-</span><span class="pln">studio</span>
Android-Studio-repo
<span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">apt-get</span><span class="pln"> update</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">apt-get</span><span class="pln"> install android</span><span class="pun">-</span><span class="pln">studio</span>
上面的安装命令会在 /opt 目录下面安装 Android Studio。
现在,运行下面的命令启动安装向导:
<span class="pln">$ </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">android</span><span class="pun">-</span><span class="pln">studio</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">studio</span><span class="pun">.</span><span class="pln">sh</span>
这会激活安装窗口。下面的截图展示了安装 Android Studio 的过程。
安装 Android Studio
安装类型
设置模拟器
你点击了 Finish 按钮之后,就会显示同意协议页面。当你接受协议之后,它就开始下载需要的组件。
下载组件
这一步完成之后就结束了 Android Studio 的安装。当你重启 Android Studio 时,你会看到下面的欢迎界面,从这里你可以开始用 Android Studio 工作了。
欢迎界面
在 CentOS 7 上安装
现在再让我们来看看如何在 CentOS 7 上安装 Android Studio。这里你同样需要安装 JDK 1.6 或者更新版本。如果你不是 root 用户,记得在命令前面使用 ‘sudo’。你可以下载最新版本的 JDK。如果你已经安装了一个比较旧的版本,在安装新的版本之前你需要先卸载旧版本。在下面的例子中,我会通过下载需要的 rpm 包安装 JDK 1.8.0_65。
<span class="pun">[</span><span class="pln">root@li1260</span><span class="pun">-</span><span class="lit">39</span><span class="pun">~]#</span><span class="pln"> rpm </span><span class="pun">-</span><span class="pln">ivh jdk</span><span class="pun">-</span><span class="lit">8u65</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x64</span><span class="pun">.</span><span class="pln">rpm</span>
<span class="typ">Preparing</span><span class="pun">...</span><span class="com">################################# [100%]</span>
<span class="typ">Updating</span><span class="pun">/</span><span class="pln"> installing</span><span class="pun">...</span>
<span class="lit">1</span><span class="pun">:</span><span class="pln">jdk1</span><span class="pun">.</span><span class="lit">8.0</span><span class="pln">_65</span><span class="pun">-</span><span class="lit">2000</span><span class="pun">:</span><span class="lit">1.8</span><span class="pun">.</span><span class="lit">0_65</span><span class="pun">-</span><span class="pln">fcs </span><span class="com">################################# [100%]</span>
<span class="typ">Unpacking</span><span class="pln"> JAR files</span><span class="pun">...</span>
<span class="pln">tools</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
<span class="pln">plugin</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
<span class="pln">javaws</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
<span class="pln">deploy</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
<span class="pln">rt</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
<span class="pln">jsse</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
<span class="pln">charsets</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
<span class="pln">localedata</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
<span class="pln">jfxrt</span><span class="pun">.</span><span class="pln">jar</span><span class="pun">...</span>
如果没有正确设置 Java 路径,你会看到错误信息。因此,设置正确的路径:
<span class="kwd">export</span><span class="pln"> JAVA_HOME</span><span class="pun">=</span><span class="str">/usr/</span><span class="pln">java</span><span class="pun">/</span><span class="pln">jdk1</span><span class="pun">.</span><span class="lit">8.0</span><span class="pln">_25</span><span class="pun">/</span>
<span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="pln">$PATH</span><span class="pun">:</span><span class="pln">$JAVA_HOME</span>
检查是否安装了正确的版本:
<span class="pun">[</span><span class="pln">root@li1260</span><span class="pun">-</span><span class="lit">39</span><span class="pun">~]#</span><span class="pln"> java </span><span class="pun">-</span><span class="pln">version</span>
<span class="pln">java version </span><span class="str">"1.8.0_65"</span>
<span class="typ">Java</span><span class="pun">(</span><span class="pln">TM</span><span class="pun">)</span><span class="pln"> SE </span><span class="typ">Runtime</span><span class="typ">Environment</span><span class="pun">(</span><span class="pln">build </span><span class="lit">1.8</span><span class="pun">.</span><span class="lit">0_65</span><span class="pun">-</span><span class="pln">b17</span><span class="pun">)</span>
<span class="typ">Java</span><span class="typ">HotSpot</span><span class="pun">(</span><span class="pln">TM</span><span class="pun">)</span><span class="lit">64</span><span class="pun">-</span><span class="typ">Bit</span><span class="typ">Server</span><span class="pln"> VM </span><span class="pun">(</span><span class="pln">build </span><span class="lit">25.65</span><span class="pun">-</span><span class="pln">b01</span><span class="pun">,</span><span class="pln"> mixed mode</span><span class="pun">)</span>
如果你安装 Android Studio 的时候看到任何类似 “unable-to-run-mksdcard-sdk-tool:” 的错误信息,你可能要在 CentOS 7 64 位系统中安装以下软件包:
- glibc.i686
- glibc-devel.i686
- libstdc++.i686
- zlib-devel.i686
- ncurses-devel.i686
- libX11-devel.i686
- libXrender.i686
- libXrandr.i686
通过从 Android 网站 下载 IDE 文件然后解压安装 studio 也是一样的。
<span class="pun">[</span><span class="pln">root@li1260</span><span class="pun">-</span><span class="lit">39</span><span class="pln"> tmp</span><span class="pun">]#</span><span class="pln"> unzip android</span><span class="pun">-</span><span class="pln">studio</span><span class="pun">-</span><span class="pln">ide</span><span class="pun">-</span><span class="lit">141.2343393</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">.</span><span class="pln">zip</span>
移动 android-studio 目录到 /opt 目录
<span class="pun">[</span><span class="pln">root@li1260</span><span class="pun">-</span><span class="lit">39</span><span class="pln"> tmp</span><span class="pun">]#</span><span class="kwd">mv</span><span class="pun">/</span><span class="pln">tmp</span><span class="pun">/</span><span class="pln">android</span><span class="pun">-</span><span class="pln">studio</span><span class="str">/ /</span><span class="pln">opt</span><span class="pun">/</span>
需要的话你可以创建一个到 studio 可执行文件的符号链接用于快速启动。
<span class="pun">[</span><span class="pln">root@li1260</span><span class="pun">-</span><span class="lit">39</span><span class="pln"> tmp</span><span class="pun">]#</span><span class="kwd">ln</span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">android</span><span class="pun">-</span><span class="pln">studio</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">studio</span><span class="pun">.</span><span class="pln">sh </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">android</span><span class="pun">-</span><span class="pln">studio</span>
现在在终端中启动 studio:
<span class="pun">[</span><span class="pln">root@localhost </span><span class="pun">~]#</span><span class="pln">studio</span>
之后用于完成安装的截图和前面 Ubuntu 安装过程中的是一样的。安装完成后,你就可以开始开发你自己的 Android 应用了。
总结
虽然发布不到一年,但是 Android Studio 已经替代 Eclipse 成为了 Android 的开发最主要的 IDE。它是唯一能支持 Google 之后将要提供的 Android SDK 和其它 Android 特性的官方 IDE 工具。那么,你还在等什么呢?赶快安装 Android Studio 来体验开发 Android 应用的乐趣吧。
更多Android Studio相关内容可以看看以下的有用链接:
Android Studio 的详细介绍:请点这里
Android Studio 的下载地址:请点这里
via: http://linoxide.com/tools/install-android-studio-ubuntu-15-04-centos-7/
作者:B N Poornima 译者:ictlyh 校对:Caroline