Location>code7788 >text

mac M1,M2,M3 chip stepping on the pit nodejs ruby brew

Popularity:914 ℃/2024-09-24 19:55:14

Problems & Solutions

First of all, the solution, interested parties can understand how things, perhaps I describe the problem is not professional, but it does solve the current problem, welcome to leave a message to discuss!

There are two main issues here, one of which is enabling therosettaPatterns fail, one is a mix of architectures that makes the project unviable.

(computing) enable (a feature)rosettaMode Failure

fulfillmentarch -x86_64 zshrecompensearch: posix_spawnp: zsh: Bad CPU type in executable
Reason: rosetta not installed

fulfillmentsoftwareupdate --install-rosettaInstallation of rosetta

Package reference  is missing installKBytes attribute

Reason: System version is low and cannot be installed, update the system

Mixed architectures lead to projects that don't run

existarm64architecture with brew installed, runarch -x86_64 zshAfter that, it causes brew to install thex86The command tool of the architecture, through thervmmountingrubyBut because of the architecture of brew, you can only installarm64The project times out when you run the project.

LoadError - dlopen(/Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/, 0x0009): tried: '/Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/' (no such file), '/Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')) - /Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/

Reason: brew installed a command tool for a different architecture
Solution: Unify the architecture, uninstall brew, and install the tools for x86 architecture.
After you execute thearch -x86_64 zsh, and installedbrewpresent situation
It might be worth checking the architecture of the installed brew

which brew
# This is the brew installed in x86 mode
/usr/local/bin/brew
# This is the brew installed in arm mode
/opt/homebrew

contexts

The company has an M3 MacBook Pro, which is really good and fast.

As a front-end developer, nodejs is essential, the company's projects need to use a low version of nodejs (<=14), here we will generally use thenvmManaging nodejs versions

So, the first step, install nvm

curl -o- /nvm-sh/nvm/v0.40.1/ | bash

By the way, we usually useiterm2Instead of the mac terminal, and using zsh as the shell interpreter, yes, install anotheroh-my-zsh

At this point you should be able to executenvmIt's an order.

# List all versions that can be installed
nvm ls-remote
# Install the latest stable version
nvm install latest

Installation of version 14 and later (>=15) is not a problem, installing 12 will have a lot of compilation information, wait for more than 10 minutes will be found to report an error, can not be used!

method settle an issue

utilizationrosettaparadigm

On Apple Silicon Macs, you can use theRosetta 2 to runx86_64 applications, including terminalshell. Usearch -x86_64 zsh command to start a file that is passed through theRosetta 2 runningzsh shellThis is so you can get a good idea of what's going on in thex86_64 environment to run commands and install software.

arch -x86_64 zsh

Under normal circumstances, we will prompt you to install theRosetta 2 , no feedback if already installed, then you can execute thenvm install 12 Installed nodejs

I can't believe I got it wrong.

arch: posix_spawnp: zsh: Bad CPU type in executable

That's what puzzles me.

Through searching, I realized that I needed to install theRosetta 2, which can be executed by executing the

softwareupdate --install-rosetta

Under normal circumstances, just wait for the installation.

And me, I've fallen into a hole again.

Package reference  is missing installKBytes attribute

I was starting to get skeptical, but then I realized it might have something to do with the version of the system, so I upgraded it.

It's really good, the nodejs environment is really fine now

emerging issue

Now that you need to run the ios project, it's a good idea to use the2.7.2(used form a nominal expression)ruby, the computer comes with 2.6, there is no way, it is better to use a ruby versioning tool -- rvm

Installing rvm requires a brew, which I'm smart enough to run.arch -x86_64 zsh I've already installed it before, I'm such aclever boy

Soon, I paid for my behavior.

rationale

Since I am performingarch -x86_64 zsh The previous installation of brew, so the tools for the brew installation are allarm64architecture, at this point I'm installing thegnupg Cue me.

Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
    arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.

At this point I'll executearch -arm64 brew install gnupginstalledarm64(I don't know what it's for), and the tool dependencies are also installed.arm64structured

As I was installing other dependencies, I was reminded to install them using the arm architecture.

A real pit.

Yes, and then I installed it.rvm, in x86 mode, usearm64structuredbrewmountedrvmAnd guess what architecture it's on-- it's still an arm64.

I can finally executervm install 2.7.2 I installed the specified version of Ruby, but I realized that it wouldn't install, so I was smart enough to install it via thearch -arm64 rvm install 2.7.2The way to install thearm64Ruby Architecture

So I went to install the project's dependencies with great joy, and the nightmare began

analogges: autoconf, automake, libtool, pkg-config, coreutils, libyaml, libksba, readline, zlib, [email protected] These dependencies, My installation should bex86architecture, which is used by the project here.bundler It doesn't matter what it is, it's a tool, just follow the commands.

fulfillmentbundler install Install the project dependencies, and then run thebundle exec pod installAnd that's when the problem arose.

LoadError - dlopen(/Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/, 0x0009): tried: '/Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/' (no such file), '/Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')) - /Users/q/.rvm/gems/ruby-2.7.2/gems/nkf-0.2.0/lib/

I saw it.have 'x86_64', need 'arm64e' or 'arm64'I knew something was wrong, and I switched the libraries toarm64architecture, still does not run, began to doubt life, so with a colleague to check the version number of the tool

I realize that ruby isarm64Architecture, Causesx86The tool did not work, but I could not install x86 ruby, and when I thought of ruby, I thought of not using rvm to manage the version, and just downloaded one, and it did work, and I gradually realized the problem.

View ruby's architecture

ruby -v
# ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin24]

Here I've switched to x86 ruby

See the architecture of the brew

Wrong way

Searched the web and found this code

brew config
HOMEBREW_VERSION: 4.3.24
ORIGIN: /Homebrew/brew
HEAD: 916044581862c32fc2365e8e9ff0b1507a98925e
Last commit: 2 days ago
Core tap JSON: 24 Sep 09:41 UTC
Core cask tap JSON: 24 Sep 09:41 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 3.3.4 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.3.4_1/bin/ruby
CPU: dodeca-core 64-bit westmere
Clang: 16.0.0 build 1600
Git: 2.39.5 => /Applications//Contents/Developer/usr/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.0-x86_64
CLT: 16.0.0.0.1.1724870825
Xcode: 16.0
Rosetta 2: true

At first glance it does seem-x86_64Skeptical, I carried it out.arch -arm64 brew config

HOMEBREW_VERSION: 4.3.24
ORIGIN: /Homebrew/brew
HEAD: 916044581862c32fc2365e8e9ff0b1507a98925e
Last commit: 2 days ago
Core tap JSON: 24 Sep 09:41 UTC
Core cask tap JSON: 24 Sep 09:41 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 3.3.4 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.3.4_1/bin/ruby
CPU: dodeca-core 64-bit westmere
Clang: 16.0.0 build 1600
Git: 2.39.5 => /Applications//Contents/Developer/usr/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.0-arm64
CLT: 16.0.0.0.1.1724870825
Xcode: 16.0
Rosetta 2: false
```
> Since I installed brew on arm64 architecture, I ran `arch -x86_64 zsh` to change the terminal architecture to x86.

### The right way
The correct way to do this is simple, look at the path where brew is executed.
``
which brew
``
```
# This is the x86 installation of brew.
/usr/local/bin/brew
```
```
# This is the brew installed in arm mode.
/opt/homebrew
```

## Summary
When configuring the environment, it is important to standardize the version, sometimes a small version can lead to differences in the operation of the project, it can be said that ``not even a small difference can lead to a huge difference``.

The problems we encountered are all caused by the processor architecture, we need to unify the development environment as much as possible.

There are two reasons why we got into this mess.
- Smarty-pants.
- System version.

Normally, with an "M-chip" mac, you have to be aware of the architectural differences.