I'm trying to install React JS on Ubuntu, but the instructions in the tutorial are only for Windows. How can I continue?
I've checked some other tutorials on the internet and I find that no two websites suggest the same things in order, also I'm not sure if it's safe to install the stuff third party websites say. I'm totally confused with this setup.
24 Answers
Assuming you do not have anything installed yet, install nodejs and npm using:
sudo apt-get install nodejs npmMake a project directory to build your app:
mkdir reactApp
cd reactAppInitialize your npm project and add all your project lib/dependencies. You can press enter for all of the questions asked during the npm init. Or you can use npm init -y to skip all questions.
npm init OR npm init -y
npm install webpack --save
npm install webpack-dev-server --save
npm install react --saveAlternatively, you can use the library created by the good facebook folks to bootstrap a react project so that you do not have to worry about webpack, babel-core and the rest... Simply run:
npm install -g create-react-appThen after it has been installed globally, you can now use it to create a project
create-react-app projectnameKeep project name all in lowercase or you will get an error (this just started of recent). When that is done,
cd projectnameand Voila!
npm start or yarn will start up your program at port 3000.
Create a folder named react
sudo apt install npmThese four commands are optional:
npm install -g babel-cli
npm install babel-preset-es2015 babel-preset-react
npm install -g browserify
npm install -g watchifyAfter installation run the following commands:
npm install -g create-react-app
create-react-app hello-world
cd hello-world
npm startYou will get something like this:
Success! Created hello-world at `/your-directory/react/hello-world`Inside that directory, you can run several commands:
Start the development server:
npm startBundle the app into static files for production:
npm run buildStart the test runner:
npm testRemove this tool and copies build dependencies, configuration files and scripts into the app directory (if you do this, you can’t go back!):
npm run eject
We suggest that you begin by typing:
cd hello-world
npm start 1 I used create-react-app for this and it's ready after typing just two commands in the terminal. Just use sudo to the commands if it doesn't work initially.
1To install Node.js:
sudo apt-get install python-software-properties
curl -sL | sudo -E bash -
sudo apt-get install nodejs
node -v
npm -v For installing React we need to install some dependencies too:
npm install -g babel-cli
npm install babel-preset-es2015 babel-preset-react
npm install -g browserify
npm install -g watchifyNow to install React:
npm install -g create-react-appTo create a project:
Go to DocumentRoot:
Create project by
create-react-app react-project cd react-project npm start
Successfully done.
0