Install Node.js and npm using Homebrew on OS X and macOS

 

Install Node.js and npm with Homebrew

First, install Homebrew.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then run brew update to make sure Homebrew is up to date.

brew update

run brew doctor to make sure your system is ready to brew. Run the command below and follow any recommendations from brew doctor.

brew doctor

Next, add Homebrew’s location to your $PATH in your .bash_profile or .zshrc file.

export PATH="/usr/local/bin:$PATH"

Next, install Node (npm will be installed with Node):

brew install node

To test out your Node and npm install, try installing Grunt (you might be asked to run with sudo):

npm install -g grunt-cli

Now you’ve installed Node.js, npm, and Grunt.


How to Uninstall Homebrew on Mac

 

  • Open the Terminal app

  • Type ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" 



Installing Homebrew on a Mac

Installation Steps

    • Open the Terminal app.
    • Type ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
    It will ask for password provide your mac password. 

    After it run and executed few scripts you should see 

    ==> Installation successful!


    satyagokavarapu@Satyanarayanas-MacBook-Pro ~ % ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in

    Bash. Please migrate to the following command:

      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"


    Password:

    ==> This script will install:

    /usr/local/bin/brew

    /usr/local/share/doc/homebrew

    /usr/local/share/man/man1/brew.1

    /usr/local/share/zsh/site-functions/_brew

    /usr/local/etc/bash_completion.d/brew

    /usr/local/Homebrew


    Press RETURN to continue or any other key to abort

    ==> Downloading and installing Homebrew...

    remote: Enumerating objects: 192, done.

    remote: Counting objects: 100% (192/192), done.

    remote: Compressing objects: 100% (15/15), done.

    remote: Total 266 (delta 184), reused 181 (delta 177), pack-reused 74

    Receiving objects: 100% (266/266), 80.68 KiB | 519.00 KiB/s, done.

    Resolving deltas: 100% (193/193), completed with 55 local objects.

    From https://github.com/Homebrew/brew

     * [new branch]          issyl0-patch-1 -> origin/issyl0-patch-1

       9bbd866fc..f260b6e7b  master         -> origin/master

     * [new branch]          tapioca-update -> origin/tapioca-update

     * [new tag]             2.4.15         -> 2.4.15

     * [new tag]             2.4.16         -> 2.4.16

    HEAD is now at f260b6e7b Merge pull request #8328 from reitermarkus/desc-cop

    Updated 3 taps (homebrew/cask-versions, homebrew/core and homebrew/cask).

    ==> New Formulae

    periscope                                                                                              sponge

    ==> Updated Formulae

    act                 checkstyle          editorconfig        ghz-web             helm                libphonenumber      mutt                pdfcpu              scrypt              vim

    anime-downloader    code-server         enchant             gitleaks            helmfile            librealsense        nasm                pgformatter         seal                wtf

    babel               conan               eslint              gleam               hexedit             lmod                nativefier          pmd                 sqlite-utils        xmrig

    ballerina           dartsim             exploitdb           gnupg               htop                logtalk             navi                pnpm                step                xxh

    benthos             deno                fastlane            gomplate            ipython             lsd                 netlify-cli         ponyc               swiftformat         zbar

    bundletool          diffoscope          feh                 google-java-format  ispc                mame                nuget               pulumi              talisman

    cadence             duckdb              folly               gravity             jfrog-cli           meilisearch         owfs                qrencode            trafficserver

    cartridge-cli       dvc                 gatsby-cli          harfbuzz            kustomize           mikutter            packer              rebar3              uptimed

    cdktf               dxpy                ghz                 hcloud              liblouis            mockolo             patchelf            rom-tools           v8

    ==> New Casks

    aleph-one                                flying-carpet                            nocturn                                  pb                                       toolreleases

    ==> Updated Casks

    aerial                            cookie                            id3-editor                        microsoft-edge                    quail                             tg-pro

    alt-tab                           datadog-agent                     ivideonclient                     missive                           redisinsight                      thunderbird

    anki                              dbeaver-community                 jabref                            nextcloud                         ringcentral                       tuxera-ntfs

    app-cleaner                       decrediton                        jamovi                            nrlquaker-winbox                  runjs                             visual-studio-code-insiders

    aquaskk                           dropbox-beta                      jellyfin                          obsidian                          sabnzbd                           voov-meeting

    beekeeper-studio                  elpass                            kafka-tool                        ocenaudio                         screen                            webcatalog

    blender                           epichrome                         keka-beta                         oolite                            segger-embedded-studio-for-arm    webtorrent

    blitz                             exodus                            keysmith                          pagico                            sensei                            whale

    brave-browser-dev                 extraterm                         kubernetic                        pastebot                          signal-beta                       whatsapp

    busycal                           feishu                            lark                              pcoipclient                       silentknight                      wormhole

    busycontacts                      fsnotes                           lockrattler                       propresenter                      softorino-youtube-converter       yojimbo

    c0re100-qbittorrent               funter                            loom                              prowritingaid                     stats                             zappy

    cacher                            grids                             lrtimelapse                       proxyman                          superproductivity                 zotero

    chromium                          hstracker                         marathon                          publish-or-perish                 swiftformat-for-xcode

    clipgrab                          icollections                      metasploit                        qiyimedia                         telegram

    ==> Deleted Casks

    alephone                                                                                               sound-blaster-command

    ==> Installation successful!

     

    How to Update Homebrew on Mac

     Open terminal and type brew update command.

    satyagokavarapu@Satyanarayanas-MacBook-Pro ~ % #brew update

    Perform String Shifts Python

    You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [direction, amount]:
    • direction can be 0 (for left shift) or 1 (for right shift). 
    • amount is the amount by which string s is to be shifted.
    • A left shift by 1 means remove the first character of s and append it to the end.
    • Similarly, a right shift by 1 means remove the last character of s and add it to the beginning.
    Return the final string after all operations.

    Example 1:
    Input: s = "abc", shift = [[0,1],[1,2]]
    Output: "cab"
    Explanation: 
    [0,1] means shift to left by 1. "abc" -> "bca"
    [1,2] means shift to right by 2. "bca" -> "cab"
    class Solution:
        def stringShift(self, s: str, shift: List[List[int]]) -> str:
            l,ls,rs = len(s),0,0
            for direction , amount in shift:
                if direction == 0:
                    ls+=amount
                else:
                    rs+=amount
            ls = ls % l
            rs = rs % l
            if ls == rs:
                return s
            elif ls > rs:
                ls = ls -rs
                return s[ls:]+s[:ls]
            else:
                rs = rs -ls
                return s[-rs:]+s[:-rs]



                
            
            
            
            
                
                
                

    Find the Difference Python

    Given two strings s and t which consist of only lowercase letters.
    String t is generated by random shuffling string s and then add one more letter at a random position.
    Find the letter that was added in t.
    Example:
    Input:
    s = "abcd"
    t = "abcde"
    
    Output:
    e
    
    Explanation:
    'e' is the letter that was added.
    Using sorting
    class Solution:
        def findTheDifference(self, s: str, t: str) -> str:
            x = sorted(s)
            y = sorted(t)
            i = 0
            while i < len(x):
                if x[i] != y[i]:
                    return y[i]
                i+=1
            return y[i]
    Time Complexity : O(nlogn)
    Space Complexity : O(1) sorting in python takes inplace so O(1)
    Using Hashmap :
    class Solution:
        def findTheDifference(self, s: str, t: str) -> str:
            counter_s = Counter(s)
            for ch in t:
                if ch not in counter_s or counter_s[ch] == 0:
                    return ch
                else:
                    counter_s[ch] -=1
    Time Complexity : O(n)
    Space Complexity : O(1)
    Using Bit manipulation :
    class Solution:
        def findTheDifference(self, s: str, t: str) -> str:
            res = 0
            for i in s:
                res ^= ord(i)
                
            for i in t:
                res ^= ord(i)
                
            return chr(res)
    Time Complexity : O(n)
    Space complexity : O(1)

    Contains Duplicate II Python

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
    Example 1:
    Input: nums = [1,2,3,1], k = 3
    Output: true
    
    Example 2:
    Input: nums = [1,0,1,1], k = 1
    Output: true
    
    Example 3:
    Input: nums = [1,2,3,1,2,3], k = 2
    Output: false
    Using Hashmap:
    class Solution:
        def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
            hashmap = {}
            for i in range(0,len(nums)):
                if nums[i] in hashmap and abs(hashmap[nums[i]] - i) <= k:
                    return True
                else:
                    hashmap[nums[i]] = i
            return False
    Time Complexity : O(n)
    Space Complexity :O(n,k) 

    Featured Post

    H1B Visa Stamping at US Consulate

      H1B Visa Stamping at US Consulate If you are outside of the US, you need to apply for US Visa at a US Consulate or a US Embassy and get H1...