Category Archives: Programming

Install or Upgrade to latest Node JS version in Ubuntu

Node Js

Node JS

We can install Node JS or upgrade currently installed version to latest version via two methods

  1. Installing latest .tar file and
  2. Node Version Manager (NVM)

Installing Node JS via .tar file

Download the latest version from https://nodejs.org/en/

At the time of writing this tutorial current version of node js is 8.11.3 LTS.

Now add it to environment variable bu running below command

Check the version of node js

Installing / upgrading Node Js via NVM

Other way to install / upgrade Node Js is via NVM (Node Version Manager) 

If it is not already installed on your machine, then follow below steps to install it, skip it already installed. You can also check these steps in the official documentation of NVM here

Run the script

Now source the profile to get the access in the current session which doesn’t require you logout and login back.

To see the list of versions available for installation run below command

To install a version that you need

Tell nvm to use currently installed version

Confirm the currently installed version by

 

Useful flutter resources

Flutter is Google’s mobile app SDK for crafting high-quality native interfaces on iOS and Android in record time. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
– flutter.io
Top articles for flutter
Flutter – SQFLITE (SQLITE) + MVP Architecture + Login App Tutorial
https://www.youtube.com/watch?v=Yzfxqd9-6QY
Building a news app
Login animation
Flutter – Build Material Chat App | Frenzy Chat For Android & iOS | Design
https://www.youtube.com/watch?v=Yd-bgqe3DxA
Best Video Tutorials Of Flutter To Develop Application For Android & ios
Music Player in Flutter
Weather forecast with rain app in Flutter
Complete Guide to Flutter: How to Build a Real World App
https://www.youtube.com/watch?v=S59b-XFsyY8&t=2452s
Flutter: Building a WhatsApp Clone from scratch | UI | Material Design
https://www.youtube.com/watch?v=2Tyrofn6zPg
Building a List in Redux with Dart’s Flutter Framework
https://www.youtube.com/watch?v=oqPUd1FlmDQ
Flutter – MVP Architecture | Design Pattern | Dependency Injection | Flavors | Demo
https://www.youtube.com/watch?v=I2AgSDAEZSE
Flutter — Container Cheat Sheet

Install Flutter on Linux

Flutter Logo

Image Credit: Google

As per Flutter documentation you should fulfill below requirement to run Flutter development environment on your machine.

  • Operating Systems: Linux (64-bit)
  • Disk Space: 600 MB (does not include disk space for IDE/tools).
  • Tools: Flutter depends on these command-line tools being available in your environment.
    • bashmkdirrmgitcurlunzipwhich

Install Flutter SDK

Flutter is currently in Beta, you can download latest version of Flutter from this url
While writing this article, the current version is 0.3.2 beta
Go to directory where you want to extract the file. For example I want to extract this in my Documents directory.

Now run below command to extract the file in the current directory

To be able to run flutter command from terminal we need to add it to our path.

This will temporarily add flutter to path, we need to make it permanent so that it will be available on restart also.


To check if it has been added to path

You should see the flutter path in the output.

Flutter comes with a handy doctor command through which you can see if all dependencies have been installed or not on your computer to run a flutter development environment.

You can upgrade flutter by running

Setup Android Studio

You should have android studio installed on your machine. To install the latest version of it, visit https://developer.android.com/studio/

Configure Text Editors

Refer this link to setup Flutter in Android Studio –

https://flutter.io/get-started/editor/#androidstudio

To setup flutter in Visual Studio Code, refer this link

https://flutter.io/get-started/editor/#vscode

Setup Device to run the application (From flutter.io)

To prepare to run and test your Flutter app on an Android device, you’ll need an Android device running Android 4.1 (API level 16) or higher.

  1. Enable Developer options and USB debugging on your device. Detailed instructions are available in the Android documentation.
  2. Windows-only: Install the Google USB Driver
  3. Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device.
  4. In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device.
  5. Start your app by running flutter run.

By default, Flutter uses the version of the Android SDK where your adb tool is based. If you want Flutter to use a different installation of the Android SDK, you must set the ANDROID_HOME environment variable to that installation directory.

Set up the Android emulator

To prepare to run and test your Flutter app on the Android emulator, follow these steps:

  1. Enable VM acceleration on your machine.
  2. Launch Android Studio>Tools>Android>AVD Manager and select Create Virtual Device.
  3. Choose a device definition and select Next.
  4. Select one or more system images for the Android versions you want to emulate, and select Next. An x86 or x86_64 image is recommended.
  5. Under Emulated Performance, select Hardware – GLES 2.0 to enable hardware acceleration.
  6. Verify the AVD configuration is correct, and select Finish.For details on the above steps, see Managing AVDs.
  7. In Android Virtual Device Manager, click Run in the toolbar. The emulator starts up and displays the default canvas for your selected OS version and device.
  8. Start your app by running flutter run. The connected device name is Android SDK built for <platform>, where platform is the chip family, such as x86.

Moving a git repository to new server

If you want to move your git repository from one server to another or say from github.com to gitlab.com or from your own server to another server, follow below steps to transfer your repo.

Step 1 – Create a bare clone  of your existing git repository

Step 2 – Now cd into the newly created directory ‘your-existing-git-repo-link.git‘  and fetch all branches

Step 3 – We have all the branches on our local machine, lets push it to new server

That’s it, you have shifted your git repo.

React Native showing default screen even after code modification

If you are building a React Native application for Android by running

and you are still getting the default React native screen,

follow below steps to fix this issue.

1.Create assets directory in android/app/src/main

2. Clear your build cache by running below command from root of your application

3. After this run

4. Now build the application by running, you should see the changes

 

Install or update nodejs usin NVM in Ubuntu

Node JS is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event driven, non-blocking I/O model that makes it lightweight and efficient
 Using nvmNVM, which stands for “Node.js version manager” we can install multiple versions of nodejs on Ubuntu.

To install or update nvm, you can use the install script using cURL: ( You can find the installation instructions on projects github page https://github.com/creationix/nvm/blob/master/README.md)


or using Wget:


Run the script by running 


To get the list of available Node.js versions

React Native Issues

Recently I started learning React Native to build native mobile applications using React JS. I faced lots of issues while making my first application run on my Ubuntu desktop. Here I am recording issues I faced and the solutions that worked for me, so that beginners like me don’t have to reinvent the wheel.

A problem occurred configuring project ‘:app’.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
  1. Go to your React native Project -> Android
  2. Create a file local.properties
  3. Open the file
  4. paste your Android SDK path like below
    • in Windows sdk.dir = C:/Users/USERNAME/AppData/Local/Android/sdk
    • in macOS sdk.dir = /Users/USERNAME/Library/Android/sdk
    • in linux sdk.dir = /home/USERNAME/Android/Sdk

Replace USERNAME with your user name

Now, Run react-native run-android in your terminal
ENOENT: no such file or directory, open ‘android/app/src/main/assets/index.android.bundle’
Manually create this directory
mkdir android/app/src/main/assets
Unable to load script from assets index.android.bundle
  1. (in project directory) mkdir android/app/src/main/assets
  2. react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
  3. react-native run-android

ou can automate the above steps by placing them in scripts part of package.json like this:

Ref: https://stackoverflow.com/questions/44446523/unable-to-load-script-from-assets-index-android-bundle-on-windows

 

Then you can just execute npm run android-linux from your command line every time.

I will keep updating this as and when I encounter new issues with solutions that worked for me.

Convert GMT to Local timezone in PHP

Following code snippet converts a date time in GMT to Local timezone.

 

Requires Doctrine DBAL Laravel migration

If you are running a migration to change the data type of a column in a table. You might come across this error message in terminal.

This error message is telling you to install doctrine/dbal to make this work. You can learn more about this package here https://github.com/doctrine/dbal

To install this package through composer, run following command in terminal.

Now you can run your migration by running

This should work now.

npm install – Please try running this command again as root/Administrator

If you are getting this error while running npm install, then you are not having write permission on .npm directory.

To get the ownership of this directory run following command

Also we need to give write permission to node_modules directory

ref – http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo