Files
react-native/website/_versioned_docs/version-0.21/getting-started-on-linux.md
T
2017-11-14 12:51:44 -08:00

29 lines
11 KiB
Markdown

---
id: version-0.21-getting-started-on-linux
original_id: getting-started-on-linux
title: getting-started-on-linux
---
<a id="content"></a><table width="100%"><tbody><tr><td><h1><a class="anchor" name="getting-started-on-linux"></a>Getting Started on Linux <a class="hash-link" href="undefined#getting-started-on-linux">#</a></h1></td><td style="text-align:right;"><a target="_blank" href="https://github.com/facebook/react-native/blob/master/docs/GettingStartedOnLinux.md">Edit on GitHub</a></td></tr></tbody></table><div><p>This guide is essentially a beginner-friendly version of the <a href="/react-native/docs/getting-started.html" target="">Getting Started</a> page for React Native on Linux.</p><h3><a class="anchor" name="prerequisites"></a>Prerequisites <a class="hash-link" href="docs/getting-started-on-linux.html#prerequisites">#</a></h3><p>For the purposes of this guide, we assume that you're working on Ubuntu Linux 14.04 LTS.</p><p>Before following this guide, you should have installed the Android SDK and run a successful Java-based "Hello World" app for Android.</p><p>See <a href="/react-native/docs/android-setup.html" target="">Android Setup</a> for details.</p><h4><a class="anchor" name="installing-nodejs"></a>Installing NodeJS <a class="hash-link" href="docs/getting-started-on-linux.html#installing-nodejs">#</a></h4><p>The first thing you need to do is to install NodeJS, a popular Javascript implementation.</p><p>Fire up the Terminal and paste the following commands to install NodeJS from the <a href="https://nodesource.com/" target="_blank">NodeSource</a> repository:</p><div class="prism language-javascript">sudo apt<span class="token operator">-</span><span class="token keyword">get</span> install <span class="token operator">-</span>y build<span class="token operator">-</span>essential
curl <span class="token operator">-</span>sL https<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>deb<span class="token punctuation">.</span>nodesource<span class="token punctuation">.</span>com<span class="token operator">/</span>setup_4<span class="token punctuation">.</span>x <span class="token operator">|</span> sudo <span class="token operator">-</span>E bash <span class="token operator">-</span>
sudo apt<span class="token operator">-</span><span class="token keyword">get</span> install <span class="token operator">-</span>y nodejs
sudo ln <span class="token operator">-</span>s <span class="token operator">/</span>usr<span class="token operator">/</span>bin<span class="token operator">/</span>nodejs <span class="token operator">/</span>usr<span class="token operator">/</span>bin<span class="token operator">/</span>node</div><p><strong>NOTE</strong>: The above instructions are for Ubuntu. If you're on a different distro, please follow the instructions on the <a href="https://nodejs.org/en/download/" target="_blank">NodeJS website</a>.</p><h4><a class="anchor" name="installing-watchman"></a>Installing Watchman <a class="hash-link" href="docs/getting-started-on-linux.html#installing-watchman">#</a></h4><p><a href="https://facebook.github.io/watchman/docs/install.html" target="_blank">watchman</a> is a tool by Facebook for watching changes in the filesystem. You need to install it for better performance and avoid a node file-watching bug.</p><p>Paste the following into your terminal to compile watchman from source and install it:</p><div class="prism language-javascript">git clone https<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>facebook<span class="token operator">/</span>watchman<span class="token punctuation">.</span>git
cd watchman
git checkout v4<span class="token number">.1</span><span class="token punctuation">.</span><span class="token number">0</span> # the latest stable release
<span class="token punctuation">.</span><span class="token operator">/</span>autogen<span class="token punctuation">.</span>sh
<span class="token punctuation">.</span><span class="token operator">/</span>configure
make
sudo make install</div><h4><a class="anchor" name="installing-flow"></a>Installing Flow <a class="hash-link" href="docs/getting-started-on-linux.html#installing-flow">#</a></h4><p>Flow is a static type checker for JavaScript. To install it, paste the following in the terminal:</p><div class="prism language-javascript">sudo npm install <span class="token operator">-</span>g flow<span class="token operator">-</span>bin</div><h2><a class="anchor" name="setting-up-an-android-device"></a>Setting up an Android Device <a class="hash-link" href="docs/getting-started-on-linux.html#setting-up-an-android-device">#</a></h2><p>Let's set up an Android device to run our starter project. </p><p>First thing is to plug in your device and check the manufacturer code by using <code>lsusb</code>, which should output something like this:</p><div class="prism language-javascript">$ lsusb
Bus <span class="token number">002</span> Device <span class="token number">002</span><span class="token punctuation">:</span> ID <span class="token number">8087</span><span class="token punctuation">:</span><span class="token number">0024</span> Intel Corp<span class="token punctuation">.</span> Integrated Rate Matching Hub
Bus <span class="token number">002</span> Device <span class="token number">001</span><span class="token punctuation">:</span> ID 1d6b<span class="token punctuation">:</span><span class="token number">0002</span> Linux Foundation <span class="token number">2.0</span> root hub
Bus <span class="token number">001</span> Device <span class="token number">003</span><span class="token punctuation">:</span> ID 22b8<span class="token punctuation">:</span><span class="token number">2e76</span> Motorola PCS
Bus <span class="token number">001</span> Device <span class="token number">002</span><span class="token punctuation">:</span> ID <span class="token number">8087</span><span class="token punctuation">:</span><span class="token number">0024</span> Intel Corp<span class="token punctuation">.</span> Integrated Rate Matching Hub
Bus <span class="token number">001</span> Device <span class="token number">001</span><span class="token punctuation">:</span> ID 1d6b<span class="token punctuation">:</span><span class="token number">0002</span> Linux Foundation <span class="token number">2.0</span> root hub
Bus <span class="token number">004</span> Device <span class="token number">001</span><span class="token punctuation">:</span> ID 1d6b<span class="token punctuation">:</span><span class="token number">0003</span> Linux Foundation <span class="token number">3.0</span> root hub
Bus <span class="token number">003</span> Device <span class="token number">001</span><span class="token punctuation">:</span> ID 1d6b<span class="token punctuation">:</span><span class="token number">0002</span> Linux Foundation <span class="token number">2.0</span> root hub</div><p>These lines represent the USB devices currently connected to your machine.</p><p>You want the line that represents your phone. If you're in doubt, try unplugging your phone and running the command again:</p><div class="prism language-javascript">$ lsusb
Bus <span class="token number">002</span> Device <span class="token number">002</span><span class="token punctuation">:</span> ID <span class="token number">8087</span><span class="token punctuation">:</span><span class="token number">0024</span> Intel Corp<span class="token punctuation">.</span> Integrated Rate Matching Hub
Bus <span class="token number">002</span> Device <span class="token number">001</span><span class="token punctuation">:</span> ID 1d6b<span class="token punctuation">:</span><span class="token number">0002</span> Linux Foundation <span class="token number">2.0</span> root hub
Bus <span class="token number">001</span> Device <span class="token number">002</span><span class="token punctuation">:</span> ID <span class="token number">8087</span><span class="token punctuation">:</span><span class="token number">0024</span> Intel Corp<span class="token punctuation">.</span> Integrated Rate Matching Hub
Bus <span class="token number">001</span> Device <span class="token number">001</span><span class="token punctuation">:</span> ID 1d6b<span class="token punctuation">:</span><span class="token number">0002</span> Linux Foundation <span class="token number">2.0</span> root hub
Bus <span class="token number">004</span> Device <span class="token number">001</span><span class="token punctuation">:</span> ID 1d6b<span class="token punctuation">:</span><span class="token number">0003</span> Linux Foundation <span class="token number">3.0</span> root hub
Bus <span class="token number">003</span> Device <span class="token number">001</span><span class="token punctuation">:</span> ID 1d6b<span class="token punctuation">:</span><span class="token number">0002</span> Linux Foundation <span class="token number">2.0</span> root hub</div><p>You'll see that after removing the phone, the line which has the phone model ("Motorola PCS" in this case) disappeared from the list. This is the line that we care about.</p><p><code>Bus 001 Device 003: ID 22b8:2e76 Motorola PCS</code></p><p>From the above line, you want to grab the first four digits from the device ID:</p><p><code>22b8:2e76</code> </p><p>In this case, it's <code>22b8</code>. That's the identifier for Motorola.</p><p>You'll need to input this into your udev rules in order to get up and running:</p><div class="prism language-javascript">echo SUBSYSTEM<span class="token operator">==</span><span class="token string">"usb"</span><span class="token punctuation">,</span> ATTR<span class="token punctuation">{</span>idVendor<span class="token punctuation">}</span><span class="token operator">==</span><span class="token string">"22b8"</span><span class="token punctuation">,</span> MODE<span class="token operator">=</span><span class="token string">"0666"</span><span class="token punctuation">,</span> GROUP<span class="token operator">=</span><span class="token string">"plugdev"</span> <span class="token operator">|</span> sudo tee <span class="token operator">/</span>etc<span class="token operator">/</span>udev<span class="token operator">/</span>rules<span class="token punctuation">.</span>d<span class="token operator">/</span><span class="token number">51</span><span class="token operator">-</span>android<span class="token operator">-</span>usb<span class="token punctuation">.</span>rules</div><p>Make sure that you replace <code>22b8</code> with the identifier you get in the above command.</p><p>Now check that your device is properly connecting to ADB, the Android Debug Bridge, by using <code>adb devices</code>.</p><div class="prism language-javascript">List of devices attached
TA9300GLMK device</div><p>For more information, please see the docs for <a href="/react-native/docs/running-on-device-android.html" target="">running an Android app on your device</a>.</p><h2><a class="anchor" name="next-steps"></a>Next Steps <a class="hash-link" href="docs/getting-started-on-linux.html#next-steps">#</a></h2><p>Your Android device and your tools are all ready to go. You can now follow the instructions in the <a href="http://facebook.github.io/react-native/docs/getting-started.html#quick-start" target="_blank">Quick Start</a> guide to install React Native and start your first project.</p></div><div class="docs-prevnext"><a class="docs-next" href="android-setup.html#content">Next →</a></div>